1 /* 2 * Copyright 2017 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 27 #include "../display_mode_lib.h" 28 #include "../display_mode_vba.h" 29 #include "../dml_inline_defs.h" 30 #include "display_rq_dlg_calc_21.h" 31 32 /* 33 * NOTE: 34 * This file is gcc-parseable HW gospel, coming straight from HW engineers. 35 * 36 * It doesn't adhere to Linux kernel style and sometimes will do things in odd 37 * ways. Unless there is something clearly wrong with it the code should 38 * remain as-is as it provides us with a guarantee from HW that it is correct. 39 */ 40 41 static void calculate_ttu_cursor( 42 struct display_mode_lib *mode_lib, 43 double *refcyc_per_req_delivery_pre_cur, 44 double *refcyc_per_req_delivery_cur, 45 double refclk_freq_in_mhz, 46 double ref_freq_to_pix_freq, 47 double hscale_pixel_rate_l, 48 double hscl_ratio, 49 double vratio_pre_l, 50 double vratio_l, 51 unsigned int cur_width, 52 enum cursor_bpp cur_bpp); 53 54 static unsigned int get_bytes_per_element(enum source_format_class source_format, bool is_chroma) 55 { 56 unsigned int ret_val = 0; 57 58 if (source_format == dm_444_16) { 59 if (!is_chroma) 60 ret_val = 2; 61 } else if (source_format == dm_444_32) { 62 if (!is_chroma) 63 ret_val = 4; 64 } else if (source_format == dm_444_64) { 65 if (!is_chroma) 66 ret_val = 8; 67 } else if (source_format == dm_420_8) { 68 if (is_chroma) 69 ret_val = 2; 70 else 71 ret_val = 1; 72 } else if (source_format == dm_420_10) { 73 if (is_chroma) 74 ret_val = 4; 75 else 76 ret_val = 2; 77 } else if (source_format == dm_444_8) { 78 ret_val = 1; 79 } 80 return ret_val; 81 } 82 83 static bool is_dual_plane(enum source_format_class source_format) 84 { 85 bool ret_val = false; 86 87 if ((source_format == dm_420_8) || (source_format == dm_420_10)) 88 ret_val = true; 89 90 return ret_val; 91 } 92 93 static double get_refcyc_per_delivery( 94 struct display_mode_lib *mode_lib, 95 double refclk_freq_in_mhz, 96 double pclk_freq_in_mhz, 97 bool odm_combine, 98 unsigned int recout_width, 99 unsigned int hactive, 100 double vratio, 101 double hscale_pixel_rate, 102 unsigned int delivery_width, 103 unsigned int req_per_swath_ub) 104 { 105 double refcyc_per_delivery = 0.0; 106 107 if (vratio <= 1.0) { 108 if (odm_combine) 109 refcyc_per_delivery = (double) refclk_freq_in_mhz 110 * dml_min((double) recout_width, (double) hactive / 2.0) 111 / pclk_freq_in_mhz / (double) req_per_swath_ub; 112 else 113 refcyc_per_delivery = (double) refclk_freq_in_mhz * (double) recout_width 114 / pclk_freq_in_mhz / (double) req_per_swath_ub; 115 } else { 116 refcyc_per_delivery = (double) refclk_freq_in_mhz * (double) delivery_width 117 / (double) hscale_pixel_rate / (double) req_per_swath_ub; 118 } 119 120 dml_print("DML_DLG: %s: refclk_freq_in_mhz = %3.2f\n", __func__, refclk_freq_in_mhz); 121 dml_print("DML_DLG: %s: pclk_freq_in_mhz = %3.2f\n", __func__, pclk_freq_in_mhz); 122 dml_print("DML_DLG: %s: recout_width = %d\n", __func__, recout_width); 123 dml_print("DML_DLG: %s: vratio = %3.2f\n", __func__, vratio); 124 dml_print("DML_DLG: %s: req_per_swath_ub = %d\n", __func__, req_per_swath_ub); 125 dml_print("DML_DLG: %s: refcyc_per_delivery= %3.2f\n", __func__, refcyc_per_delivery); 126 127 return refcyc_per_delivery; 128 129 } 130 131 static unsigned int get_blk_size_bytes(const enum source_macro_tile_size tile_size) 132 { 133 if (tile_size == dm_256k_tile) 134 return (256 * 1024); 135 else if (tile_size == dm_64k_tile) 136 return (64 * 1024); 137 else 138 return (4 * 1024); 139 } 140 141 static void extract_rq_sizing_regs( 142 struct display_mode_lib *mode_lib, 143 display_data_rq_regs_st *rq_regs, 144 const display_data_rq_sizing_params_st rq_sizing) 145 { 146 dml_print("DML_DLG: %s: rq_sizing param\n", __func__); 147 print__data_rq_sizing_params_st(mode_lib, rq_sizing); 148 149 rq_regs->chunk_size = dml_log2(rq_sizing.chunk_bytes) - 10; 150 151 if (rq_sizing.min_chunk_bytes == 0) 152 rq_regs->min_chunk_size = 0; 153 else 154 rq_regs->min_chunk_size = dml_log2(rq_sizing.min_chunk_bytes) - 8 + 1; 155 156 rq_regs->meta_chunk_size = dml_log2(rq_sizing.meta_chunk_bytes) - 10; 157 if (rq_sizing.min_meta_chunk_bytes == 0) 158 rq_regs->min_meta_chunk_size = 0; 159 else 160 rq_regs->min_meta_chunk_size = dml_log2(rq_sizing.min_meta_chunk_bytes) - 6 + 1; 161 162 rq_regs->dpte_group_size = dml_log2(rq_sizing.dpte_group_bytes) - 6; 163 rq_regs->mpte_group_size = dml_log2(rq_sizing.mpte_group_bytes) - 6; 164 } 165 166 static void extract_rq_regs( 167 struct display_mode_lib *mode_lib, 168 display_rq_regs_st *rq_regs, 169 const display_rq_params_st rq_param) 170 { 171 unsigned int detile_buf_size_in_bytes = mode_lib->ip.det_buffer_size_kbytes * 1024; 172 unsigned int detile_buf_plane1_addr = 0; 173 174 extract_rq_sizing_regs(mode_lib, &(rq_regs->rq_regs_l), rq_param.sizing.rq_l); 175 176 rq_regs->rq_regs_l.pte_row_height_linear = dml_floor( 177 dml_log2(rq_param.dlg.rq_l.dpte_row_height), 178 1) - 3; 179 180 if (rq_param.yuv420) { 181 extract_rq_sizing_regs(mode_lib, &(rq_regs->rq_regs_c), rq_param.sizing.rq_c); 182 rq_regs->rq_regs_c.pte_row_height_linear = dml_floor( 183 dml_log2(rq_param.dlg.rq_c.dpte_row_height), 184 1) - 3; 185 } 186 187 rq_regs->rq_regs_l.swath_height = dml_log2(rq_param.dlg.rq_l.swath_height); 188 rq_regs->rq_regs_c.swath_height = dml_log2(rq_param.dlg.rq_c.swath_height); 189 190 // FIXME: take the max between luma, chroma chunk size? 191 // okay for now, as we are setting chunk_bytes to 8kb anyways 192 if (rq_param.sizing.rq_l.chunk_bytes >= 32 * 1024) { //32kb 193 rq_regs->drq_expansion_mode = 0; 194 } else { 195 rq_regs->drq_expansion_mode = 2; 196 } 197 rq_regs->prq_expansion_mode = 1; 198 rq_regs->mrq_expansion_mode = 1; 199 rq_regs->crq_expansion_mode = 1; 200 201 if (rq_param.yuv420) { 202 if ((double) rq_param.misc.rq_l.stored_swath_bytes 203 / (double) rq_param.misc.rq_c.stored_swath_bytes <= 1.5) { 204 detile_buf_plane1_addr = (detile_buf_size_in_bytes / 2.0 / 64.0); // half to chroma 205 } else { 206 detile_buf_plane1_addr = dml_round_to_multiple( 207 (unsigned int) ((2.0 * detile_buf_size_in_bytes) / 3.0), 208 256, 209 0) / 64.0; // 2/3 to chroma 210 } 211 } 212 rq_regs->plane1_base_address = detile_buf_plane1_addr; 213 } 214 215 static void handle_det_buf_split( 216 struct display_mode_lib *mode_lib, 217 display_rq_params_st *rq_param, 218 const display_pipe_source_params_st pipe_src_param) 219 { 220 unsigned int total_swath_bytes = 0; 221 unsigned int swath_bytes_l = 0; 222 unsigned int swath_bytes_c = 0; 223 unsigned int full_swath_bytes_packed_l = 0; 224 unsigned int full_swath_bytes_packed_c = 0; 225 bool req128_l = false; 226 bool req128_c = false; 227 bool surf_linear = (pipe_src_param.sw_mode == dm_sw_linear); 228 bool surf_vert = (pipe_src_param.source_scan == dm_vert); 229 unsigned int log2_swath_height_l = 0; 230 unsigned int log2_swath_height_c = 0; 231 unsigned int detile_buf_size_in_bytes = mode_lib->ip.det_buffer_size_kbytes * 1024; 232 233 full_swath_bytes_packed_l = rq_param->misc.rq_l.full_swath_bytes; 234 full_swath_bytes_packed_c = rq_param->misc.rq_c.full_swath_bytes; 235 236 if (rq_param->yuv420_10bpc) { 237 full_swath_bytes_packed_l = dml_round_to_multiple( 238 rq_param->misc.rq_l.full_swath_bytes * 2 / 3, 239 256, 240 1) + 256; 241 full_swath_bytes_packed_c = dml_round_to_multiple( 242 rq_param->misc.rq_c.full_swath_bytes * 2 / 3, 243 256, 244 1) + 256; 245 } 246 247 if (rq_param->yuv420) { 248 total_swath_bytes = 2 * full_swath_bytes_packed_l + 2 * full_swath_bytes_packed_c; 249 250 if (total_swath_bytes <= detile_buf_size_in_bytes) { //full 256b request 251 req128_l = false; 252 req128_c = false; 253 swath_bytes_l = full_swath_bytes_packed_l; 254 swath_bytes_c = full_swath_bytes_packed_c; 255 } else { //128b request (for luma only for yuv420 8bpc) 256 req128_l = true; 257 req128_c = false; 258 swath_bytes_l = full_swath_bytes_packed_l / 2; 259 swath_bytes_c = full_swath_bytes_packed_c; 260 } 261 // Note: assumption, the config that pass in will fit into 262 // the detiled buffer. 263 } else { 264 total_swath_bytes = 2 * full_swath_bytes_packed_l; 265 266 if (total_swath_bytes <= detile_buf_size_in_bytes) 267 req128_l = false; 268 else 269 req128_l = true; 270 271 swath_bytes_l = total_swath_bytes; 272 swath_bytes_c = 0; 273 } 274 rq_param->misc.rq_l.stored_swath_bytes = swath_bytes_l; 275 rq_param->misc.rq_c.stored_swath_bytes = swath_bytes_c; 276 277 if (surf_linear) { 278 log2_swath_height_l = 0; 279 log2_swath_height_c = 0; 280 } else if (!surf_vert) { 281 log2_swath_height_l = dml_log2(rq_param->misc.rq_l.blk256_height) - req128_l; 282 log2_swath_height_c = dml_log2(rq_param->misc.rq_c.blk256_height) - req128_c; 283 } else { 284 log2_swath_height_l = dml_log2(rq_param->misc.rq_l.blk256_width) - req128_l; 285 log2_swath_height_c = dml_log2(rq_param->misc.rq_c.blk256_width) - req128_c; 286 } 287 rq_param->dlg.rq_l.swath_height = 1 << log2_swath_height_l; 288 rq_param->dlg.rq_c.swath_height = 1 << log2_swath_height_c; 289 290 dml_print("DML_DLG: %s: req128_l = %0d\n", __func__, req128_l); 291 dml_print("DML_DLG: %s: req128_c = %0d\n", __func__, req128_c); 292 dml_print( 293 "DML_DLG: %s: full_swath_bytes_packed_l = %0d\n", 294 __func__, 295 full_swath_bytes_packed_l); 296 dml_print( 297 "DML_DLG: %s: full_swath_bytes_packed_c = %0d\n", 298 __func__, 299 full_swath_bytes_packed_c); 300 } 301 302 static void get_meta_and_pte_attr( 303 struct display_mode_lib *mode_lib, 304 display_data_rq_dlg_params_st *rq_dlg_param, 305 display_data_rq_misc_params_st *rq_misc_param, 306 display_data_rq_sizing_params_st *rq_sizing_param, 307 unsigned int vp_width, 308 unsigned int vp_height, 309 unsigned int data_pitch, 310 unsigned int meta_pitch, 311 unsigned int source_format, 312 unsigned int tiling, 313 unsigned int macro_tile_size, 314 unsigned int source_scan, 315 unsigned int hostvm_enable, 316 unsigned int is_chroma) 317 { 318 bool surf_linear = (tiling == dm_sw_linear); 319 bool surf_vert = (source_scan == dm_vert); 320 321 unsigned int bytes_per_element; 322 unsigned int bytes_per_element_y = get_bytes_per_element( 323 (enum source_format_class) (source_format), 324 false); 325 unsigned int bytes_per_element_c = get_bytes_per_element( 326 (enum source_format_class) (source_format), 327 true); 328 329 unsigned int blk256_width = 0; 330 unsigned int blk256_height = 0; 331 332 unsigned int blk256_width_y = 0; 333 unsigned int blk256_height_y = 0; 334 unsigned int blk256_width_c = 0; 335 unsigned int blk256_height_c = 0; 336 unsigned int log2_bytes_per_element; 337 unsigned int log2_blk256_width; 338 unsigned int log2_blk256_height; 339 unsigned int blk_bytes; 340 unsigned int log2_blk_bytes; 341 unsigned int log2_blk_height; 342 unsigned int log2_blk_width; 343 unsigned int log2_meta_req_bytes; 344 unsigned int log2_meta_req_height; 345 unsigned int log2_meta_req_width; 346 unsigned int meta_req_width; 347 unsigned int meta_req_height; 348 unsigned int log2_meta_row_height; 349 unsigned int meta_row_width_ub; 350 unsigned int log2_meta_chunk_bytes; 351 unsigned int log2_meta_chunk_height; 352 353 //full sized meta chunk width in unit of data elements 354 unsigned int log2_meta_chunk_width; 355 unsigned int log2_min_meta_chunk_bytes; 356 unsigned int min_meta_chunk_width; 357 unsigned int meta_chunk_width; 358 unsigned int meta_chunk_per_row_int; 359 unsigned int meta_row_remainder; 360 unsigned int meta_chunk_threshold; 361 unsigned int meta_blk_bytes; 362 unsigned int meta_blk_height; 363 unsigned int meta_blk_width; 364 unsigned int meta_surface_bytes; 365 unsigned int vmpg_bytes; 366 unsigned int meta_pte_req_per_frame_ub; 367 unsigned int meta_pte_bytes_per_frame_ub; 368 const unsigned int log2_vmpg_bytes = dml_log2(mode_lib->soc.vmm_page_size_bytes); 369 const unsigned int dpte_buf_in_pte_reqs = 370 mode_lib->ip.dpte_buffer_size_in_pte_reqs_luma + mode_lib->ip.dpte_buffer_size_in_pte_reqs_chroma; 371 const unsigned int pde_proc_buffer_size_64k_reqs = 372 mode_lib->ip.pde_proc_buffer_size_64k_reqs; 373 374 unsigned int log2_vmpg_height = 0; 375 unsigned int log2_vmpg_width = 0; 376 unsigned int log2_dpte_req_height_ptes = 0; 377 unsigned int log2_dpte_req_height = 0; 378 unsigned int log2_dpte_req_width = 0; 379 unsigned int log2_dpte_row_height_linear = 0; 380 unsigned int log2_dpte_row_height = 0; 381 unsigned int log2_dpte_group_width = 0; 382 unsigned int dpte_row_width_ub = 0; 383 unsigned int dpte_req_height = 0; 384 unsigned int dpte_req_width = 0; 385 unsigned int dpte_group_width = 0; 386 unsigned int log2_dpte_group_bytes = 0; 387 unsigned int log2_dpte_group_length = 0; 388 unsigned int pde_buf_entries; 389 bool yuv420 = (source_format == dm_420_8 || source_format == dm_420_10); 390 391 Calculate256BBlockSizes( 392 (enum source_format_class) (source_format), 393 (enum dm_swizzle_mode) (tiling), 394 bytes_per_element_y, 395 bytes_per_element_c, 396 &blk256_height_y, 397 &blk256_height_c, 398 &blk256_width_y, 399 &blk256_width_c); 400 401 if (!is_chroma) { 402 blk256_width = blk256_width_y; 403 blk256_height = blk256_height_y; 404 bytes_per_element = bytes_per_element_y; 405 } else { 406 blk256_width = blk256_width_c; 407 blk256_height = blk256_height_c; 408 bytes_per_element = bytes_per_element_c; 409 } 410 411 log2_bytes_per_element = dml_log2(bytes_per_element); 412 413 dml_print("DML_DLG: %s: surf_linear = %d\n", __func__, surf_linear); 414 dml_print("DML_DLG: %s: surf_vert = %d\n", __func__, surf_vert); 415 dml_print("DML_DLG: %s: blk256_width = %d\n", __func__, blk256_width); 416 dml_print("DML_DLG: %s: blk256_height = %d\n", __func__, blk256_height); 417 418 log2_blk256_width = dml_log2((double) blk256_width); 419 log2_blk256_height = dml_log2((double) blk256_height); 420 blk_bytes = surf_linear ? 421 256 : get_blk_size_bytes((enum source_macro_tile_size) macro_tile_size); 422 log2_blk_bytes = dml_log2((double) blk_bytes); 423 log2_blk_height = 0; 424 log2_blk_width = 0; 425 426 // remember log rule 427 // "+" in log is multiply 428 // "-" in log is divide 429 // "/2" is like square root 430 // blk is vertical biased 431 if (tiling != dm_sw_linear) 432 log2_blk_height = log2_blk256_height 433 + dml_ceil((double) (log2_blk_bytes - 8) / 2.0, 1); 434 else 435 log2_blk_height = 0; // blk height of 1 436 437 log2_blk_width = log2_blk_bytes - log2_bytes_per_element - log2_blk_height; 438 439 if (!surf_vert) { 440 rq_dlg_param->swath_width_ub = dml_round_to_multiple(vp_width - 1, blk256_width, 1) 441 + blk256_width; 442 rq_dlg_param->req_per_swath_ub = rq_dlg_param->swath_width_ub >> log2_blk256_width; 443 } else { 444 rq_dlg_param->swath_width_ub = dml_round_to_multiple( 445 vp_height - 1, 446 blk256_height, 447 1) + blk256_height; 448 rq_dlg_param->req_per_swath_ub = rq_dlg_param->swath_width_ub >> log2_blk256_height; 449 } 450 451 if (!surf_vert) 452 rq_misc_param->full_swath_bytes = rq_dlg_param->swath_width_ub * blk256_height 453 * bytes_per_element; 454 else 455 rq_misc_param->full_swath_bytes = rq_dlg_param->swath_width_ub * blk256_width 456 * bytes_per_element; 457 458 rq_misc_param->blk256_height = blk256_height; 459 rq_misc_param->blk256_width = blk256_width; 460 461 // ------- 462 // meta 463 // ------- 464 log2_meta_req_bytes = 6; // meta request is 64b and is 8x8byte meta element 465 466 // each 64b meta request for dcn is 8x8 meta elements and 467 // a meta element covers one 256b block of the the data surface. 468 log2_meta_req_height = log2_blk256_height + 3; // meta req is 8x8 byte, each byte represent 1 blk256 469 log2_meta_req_width = log2_meta_req_bytes + 8 - log2_bytes_per_element 470 - log2_meta_req_height; 471 meta_req_width = 1 << log2_meta_req_width; 472 meta_req_height = 1 << log2_meta_req_height; 473 log2_meta_row_height = 0; 474 meta_row_width_ub = 0; 475 476 // the dimensions of a meta row are meta_row_width x meta_row_height in elements. 477 // calculate upper bound of the meta_row_width 478 if (!surf_vert) { 479 log2_meta_row_height = log2_meta_req_height; 480 meta_row_width_ub = dml_round_to_multiple(vp_width - 1, meta_req_width, 1) 481 + meta_req_width; 482 rq_dlg_param->meta_req_per_row_ub = meta_row_width_ub / meta_req_width; 483 } else { 484 log2_meta_row_height = log2_meta_req_width; 485 meta_row_width_ub = dml_round_to_multiple(vp_height - 1, meta_req_height, 1) 486 + meta_req_height; 487 rq_dlg_param->meta_req_per_row_ub = meta_row_width_ub / meta_req_height; 488 } 489 rq_dlg_param->meta_bytes_per_row_ub = rq_dlg_param->meta_req_per_row_ub * 64; 490 491 rq_dlg_param->meta_row_height = 1 << log2_meta_row_height; 492 493 log2_meta_chunk_bytes = dml_log2(rq_sizing_param->meta_chunk_bytes); 494 log2_meta_chunk_height = log2_meta_row_height; 495 496 //full sized meta chunk width in unit of data elements 497 log2_meta_chunk_width = log2_meta_chunk_bytes + 8 - log2_bytes_per_element 498 - log2_meta_chunk_height; 499 log2_min_meta_chunk_bytes = dml_log2(rq_sizing_param->min_meta_chunk_bytes); 500 min_meta_chunk_width = 1 501 << (log2_min_meta_chunk_bytes + 8 - log2_bytes_per_element 502 - log2_meta_chunk_height); 503 meta_chunk_width = 1 << log2_meta_chunk_width; 504 meta_chunk_per_row_int = (unsigned int) (meta_row_width_ub / meta_chunk_width); 505 meta_row_remainder = meta_row_width_ub % meta_chunk_width; 506 meta_chunk_threshold = 0; 507 meta_blk_bytes = 4096; 508 meta_blk_height = blk256_height * 64; 509 meta_blk_width = meta_blk_bytes * 256 / bytes_per_element / meta_blk_height; 510 meta_surface_bytes = meta_pitch 511 * (dml_round_to_multiple(vp_height - 1, meta_blk_height, 1) 512 + meta_blk_height) * bytes_per_element / 256; 513 vmpg_bytes = mode_lib->soc.vmm_page_size_bytes; 514 meta_pte_req_per_frame_ub = (dml_round_to_multiple( 515 meta_surface_bytes - vmpg_bytes, 516 8 * vmpg_bytes, 517 1) + 8 * vmpg_bytes) / (8 * vmpg_bytes); 518 meta_pte_bytes_per_frame_ub = meta_pte_req_per_frame_ub * 64; //64B mpte request 519 rq_dlg_param->meta_pte_bytes_per_frame_ub = meta_pte_bytes_per_frame_ub; 520 521 dml_print("DML_DLG: %s: meta_blk_height = %d\n", __func__, meta_blk_height); 522 dml_print("DML_DLG: %s: meta_blk_width = %d\n", __func__, meta_blk_width); 523 dml_print("DML_DLG: %s: meta_surface_bytes = %d\n", __func__, meta_surface_bytes); 524 dml_print( 525 "DML_DLG: %s: meta_pte_req_per_frame_ub = %d\n", 526 __func__, 527 meta_pte_req_per_frame_ub); 528 dml_print( 529 "DML_DLG: %s: meta_pte_bytes_per_frame_ub = %d\n", 530 __func__, 531 meta_pte_bytes_per_frame_ub); 532 533 if (!surf_vert) 534 meta_chunk_threshold = 2 * min_meta_chunk_width - meta_req_width; 535 else 536 meta_chunk_threshold = 2 * min_meta_chunk_width - meta_req_height; 537 538 if (meta_row_remainder <= meta_chunk_threshold) 539 rq_dlg_param->meta_chunks_per_row_ub = meta_chunk_per_row_int + 1; 540 else 541 rq_dlg_param->meta_chunks_per_row_ub = meta_chunk_per_row_int + 2; 542 543 // ------ 544 // dpte 545 // ------ 546 if (surf_linear) { 547 log2_vmpg_height = 0; // one line high 548 } else { 549 log2_vmpg_height = (log2_vmpg_bytes - 8) / 2 + log2_blk256_height; 550 } 551 log2_vmpg_width = log2_vmpg_bytes - log2_bytes_per_element - log2_vmpg_height; 552 553 // only 3 possible shapes for dpte request in dimensions of ptes: 8x1, 4x2, 2x4. 554 if (surf_linear) { //one 64B PTE request returns 8 PTEs 555 log2_dpte_req_height_ptes = 0; 556 log2_dpte_req_width = log2_vmpg_width + 3; 557 log2_dpte_req_height = 0; 558 } else if (log2_blk_bytes == 12) { //4KB tile means 4kB page size 559 //one 64B req gives 8x1 PTEs for 4KB tile 560 log2_dpte_req_height_ptes = 0; 561 log2_dpte_req_width = log2_blk_width + 3; 562 log2_dpte_req_height = log2_blk_height + 0; 563 } else if ((log2_blk_bytes >= 16) && (log2_vmpg_bytes == 12)) { // tile block >= 64KB 564 //two 64B reqs of 2x4 PTEs give 16 PTEs to cover 64KB 565 log2_dpte_req_height_ptes = 4; 566 log2_dpte_req_width = log2_blk256_width + 4; // log2_64KB_width 567 log2_dpte_req_height = log2_blk256_height + 4; // log2_64KB_height 568 } else { //64KB page size and must 64KB tile block 569 //one 64B req gives 8x1 PTEs for 64KB tile 570 log2_dpte_req_height_ptes = 0; 571 log2_dpte_req_width = log2_blk_width + 3; 572 log2_dpte_req_height = log2_blk_height + 0; 573 } 574 575 // The dpte request dimensions in data elements is dpte_req_width x dpte_req_height 576 // log2_vmpg_width is how much 1 pte represent, now calculating how much a 64b pte req represent 577 // That depends on the pte shape (i.e. 8x1, 4x2, 2x4) 578 //log2_dpte_req_height = log2_vmpg_height + log2_dpte_req_height_ptes; 579 //log2_dpte_req_width = log2_vmpg_width + log2_dpte_req_width_ptes; 580 dpte_req_height = 1 << log2_dpte_req_height; 581 dpte_req_width = 1 << log2_dpte_req_width; 582 583 // calculate pitch dpte row buffer can hold 584 // round the result down to a power of two. 585 pde_buf_entries = 586 yuv420 ? (pde_proc_buffer_size_64k_reqs >> 1) : pde_proc_buffer_size_64k_reqs; 587 if (surf_linear) { 588 unsigned int dpte_row_height; 589 590 log2_dpte_row_height_linear = dml_floor( 591 dml_log2( 592 dml_min( 593 64 * 1024 * pde_buf_entries 594 / bytes_per_element, 595 dpte_buf_in_pte_reqs 596 * dpte_req_width) 597 / data_pitch), 598 1); 599 600 ASSERT(log2_dpte_row_height_linear >= 3); 601 602 if (log2_dpte_row_height_linear > 7) 603 log2_dpte_row_height_linear = 7; 604 605 log2_dpte_row_height = log2_dpte_row_height_linear; 606 // For linear, the dpte row is pitch dependent and the pte requests wrap at the pitch boundary. 607 // the dpte_row_width_ub is the upper bound of data_pitch*dpte_row_height in elements with this unique buffering. 608 dpte_row_height = 1 << log2_dpte_row_height; 609 dpte_row_width_ub = dml_round_to_multiple( 610 data_pitch * dpte_row_height - 1, 611 dpte_req_width, 612 1) + dpte_req_width; 613 rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_width; 614 } else { 615 // the upper bound of the dpte_row_width without dependency on viewport position follows. 616 // for tiled mode, row height is the same as req height and row store up to vp size upper bound 617 if (!surf_vert) { 618 log2_dpte_row_height = log2_dpte_req_height; 619 dpte_row_width_ub = dml_round_to_multiple(vp_width - 1, dpte_req_width, 1) 620 + dpte_req_width; 621 rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_width; 622 } else { 623 log2_dpte_row_height = 624 (log2_blk_width < log2_dpte_req_width) ? 625 log2_blk_width : log2_dpte_req_width; 626 dpte_row_width_ub = dml_round_to_multiple(vp_height - 1, dpte_req_height, 1) 627 + dpte_req_height; 628 rq_dlg_param->dpte_req_per_row_ub = dpte_row_width_ub / dpte_req_height; 629 } 630 } 631 if (log2_blk_bytes >= 16 && log2_vmpg_bytes == 12) // tile block >= 64KB 632 rq_dlg_param->dpte_bytes_per_row_ub = rq_dlg_param->dpte_req_per_row_ub * 128; //2*64B dpte request 633 else 634 rq_dlg_param->dpte_bytes_per_row_ub = rq_dlg_param->dpte_req_per_row_ub * 64; //64B dpte request 635 636 rq_dlg_param->dpte_row_height = 1 << log2_dpte_row_height; 637 638 // the dpte_group_bytes is reduced for the specific case of vertical 639 // access of a tile surface that has dpte request of 8x1 ptes. 640 641 if (hostvm_enable) 642 rq_sizing_param->dpte_group_bytes = 512; 643 else { 644 if (!surf_linear & (log2_dpte_req_height_ptes == 0) & surf_vert) //reduced, in this case, will have page fault within a group 645 rq_sizing_param->dpte_group_bytes = 512; 646 else 647 //full size 648 rq_sizing_param->dpte_group_bytes = 2048; 649 } 650 651 //since pte request size is 64byte, the number of data pte requests per full sized group is as follows. 652 log2_dpte_group_bytes = dml_log2(rq_sizing_param->dpte_group_bytes); 653 log2_dpte_group_length = log2_dpte_group_bytes - 6; //length in 64b requests 654 655 // full sized data pte group width in elements 656 if (!surf_vert) 657 log2_dpte_group_width = log2_dpte_group_length + log2_dpte_req_width; 658 else 659 log2_dpte_group_width = log2_dpte_group_length + log2_dpte_req_height; 660 661 //But if the tile block >=64KB and the page size is 4KB, then each dPTE request is 2*64B 662 if ((log2_blk_bytes >= 16) && (log2_vmpg_bytes == 12)) // tile block >= 64KB 663 log2_dpte_group_width = log2_dpte_group_width - 1; 664 665 dpte_group_width = 1 << log2_dpte_group_width; 666 667 // since dpte groups are only aligned to dpte_req_width and not dpte_group_width, 668 // the upper bound for the dpte groups per row is as follows. 669 rq_dlg_param->dpte_groups_per_row_ub = dml_ceil( 670 (double) dpte_row_width_ub / dpte_group_width, 671 1); 672 } 673 674 static void get_surf_rq_param( 675 struct display_mode_lib *mode_lib, 676 display_data_rq_sizing_params_st *rq_sizing_param, 677 display_data_rq_dlg_params_st *rq_dlg_param, 678 display_data_rq_misc_params_st *rq_misc_param, 679 const display_pipe_params_st pipe_param, 680 bool is_chroma) 681 { 682 bool mode_422 = false; 683 unsigned int vp_width = 0; 684 unsigned int vp_height = 0; 685 unsigned int data_pitch = 0; 686 unsigned int meta_pitch = 0; 687 unsigned int ppe = mode_422 ? 2 : 1; 688 689 // FIXME check if ppe apply for both luma and chroma in 422 case 690 if (is_chroma) { 691 vp_width = pipe_param.src.viewport_width_c / ppe; 692 vp_height = pipe_param.src.viewport_height_c; 693 data_pitch = pipe_param.src.data_pitch_c; 694 meta_pitch = pipe_param.src.meta_pitch_c; 695 } else { 696 vp_width = pipe_param.src.viewport_width / ppe; 697 vp_height = pipe_param.src.viewport_height; 698 data_pitch = pipe_param.src.data_pitch; 699 meta_pitch = pipe_param.src.meta_pitch; 700 } 701 702 if (pipe_param.dest.odm_combine) { 703 unsigned int access_dir; 704 unsigned int full_src_vp_width; 705 unsigned int hactive_half; 706 unsigned int src_hactive_half; 707 access_dir = (pipe_param.src.source_scan == dm_vert); // vp access direction: horizontal or vertical accessed 708 hactive_half = pipe_param.dest.hactive / 2; 709 if (is_chroma) { 710 full_src_vp_width = pipe_param.scale_ratio_depth.hscl_ratio_c * pipe_param.dest.full_recout_width; 711 src_hactive_half = pipe_param.scale_ratio_depth.hscl_ratio_c * hactive_half; 712 } else { 713 full_src_vp_width = pipe_param.scale_ratio_depth.hscl_ratio * pipe_param.dest.full_recout_width; 714 src_hactive_half = pipe_param.scale_ratio_depth.hscl_ratio * hactive_half; 715 } 716 717 if (access_dir == 0) { 718 vp_width = dml_min(full_src_vp_width, src_hactive_half); 719 dml_print("DML_DLG: %s: vp_width = %d\n", __func__, vp_width); 720 } else { 721 vp_height = dml_min(full_src_vp_width, src_hactive_half); 722 dml_print("DML_DLG: %s: vp_height = %d\n", __func__, vp_height); 723 724 } 725 dml_print("DML_DLG: %s: full_src_vp_width = %d\n", __func__, full_src_vp_width); 726 dml_print("DML_DLG: %s: hactive_half = %d\n", __func__, hactive_half); 727 dml_print("DML_DLG: %s: src_hactive_half = %d\n", __func__, src_hactive_half); 728 } 729 rq_sizing_param->chunk_bytes = 8192; 730 731 if (rq_sizing_param->chunk_bytes == 64 * 1024) 732 rq_sizing_param->min_chunk_bytes = 0; 733 else 734 rq_sizing_param->min_chunk_bytes = 1024; 735 736 rq_sizing_param->meta_chunk_bytes = 2048; 737 rq_sizing_param->min_meta_chunk_bytes = 256; 738 739 if (pipe_param.src.hostvm) 740 rq_sizing_param->mpte_group_bytes = 512; 741 else 742 rq_sizing_param->mpte_group_bytes = 2048; 743 744 get_meta_and_pte_attr( 745 mode_lib, 746 rq_dlg_param, 747 rq_misc_param, 748 rq_sizing_param, 749 vp_width, 750 vp_height, 751 data_pitch, 752 meta_pitch, 753 pipe_param.src.source_format, 754 pipe_param.src.sw_mode, 755 pipe_param.src.macro_tile_size, 756 pipe_param.src.source_scan, 757 pipe_param.src.hostvm, 758 is_chroma); 759 } 760 761 static void dml_rq_dlg_get_rq_params( 762 struct display_mode_lib *mode_lib, 763 display_rq_params_st *rq_param, 764 const display_pipe_params_st pipe_param) 765 { 766 // get param for luma surface 767 rq_param->yuv420 = pipe_param.src.source_format == dm_420_8 768 || pipe_param.src.source_format == dm_420_10; 769 rq_param->yuv420_10bpc = pipe_param.src.source_format == dm_420_10; 770 771 get_surf_rq_param( 772 mode_lib, 773 &(rq_param->sizing.rq_l), 774 &(rq_param->dlg.rq_l), 775 &(rq_param->misc.rq_l), 776 pipe_param, 777 0); 778 779 if (is_dual_plane((enum source_format_class) (pipe_param.src.source_format))) { 780 // get param for chroma surface 781 get_surf_rq_param( 782 mode_lib, 783 &(rq_param->sizing.rq_c), 784 &(rq_param->dlg.rq_c), 785 &(rq_param->misc.rq_c), 786 pipe_param, 787 1); 788 } 789 790 // calculate how to split the det buffer space between luma and chroma 791 handle_det_buf_split(mode_lib, rq_param, pipe_param.src); 792 print__rq_params_st(mode_lib, *rq_param); 793 } 794 795 void dml21_rq_dlg_get_rq_reg( 796 struct display_mode_lib *mode_lib, 797 display_rq_regs_st *rq_regs, 798 const display_pipe_params_st pipe_param) 799 { 800 display_rq_params_st rq_param = {0}; 801 802 memset(rq_regs, 0, sizeof(*rq_regs)); 803 dml_rq_dlg_get_rq_params(mode_lib, &rq_param, pipe_param); 804 extract_rq_regs(mode_lib, rq_regs, rq_param); 805 806 print__rq_regs_st(mode_lib, *rq_regs); 807 } 808 809 // Note: currently taken in as is. 810 // Nice to decouple code from hw register implement and extract code that are repeated for luma and chroma. 811 static void dml_rq_dlg_get_dlg_params( 812 struct display_mode_lib *mode_lib, 813 const display_e2e_pipe_params_st *e2e_pipe_param, 814 const unsigned int num_pipes, 815 const unsigned int pipe_idx, 816 display_dlg_regs_st *disp_dlg_regs, 817 display_ttu_regs_st *disp_ttu_regs, 818 const display_rq_dlg_params_st rq_dlg_param, 819 const display_dlg_sys_params_st dlg_sys_param, 820 const bool cstate_en, 821 const bool pstate_en) 822 { 823 const display_pipe_source_params_st *src = &e2e_pipe_param[pipe_idx].pipe.src; 824 const display_pipe_dest_params_st *dst = &e2e_pipe_param[pipe_idx].pipe.dest; 825 const display_output_params_st *dout = &e2e_pipe_param[pipe_idx].dout; 826 const display_clocks_and_cfg_st *clks = &e2e_pipe_param[pipe_idx].clks_cfg; 827 const scaler_ratio_depth_st *scl = &e2e_pipe_param[pipe_idx].pipe.scale_ratio_depth; 828 const scaler_taps_st *taps = &e2e_pipe_param[pipe_idx].pipe.scale_taps; 829 830 // ------------------------- 831 // Section 1.15.2.1: OTG dependent Params 832 // ------------------------- 833 // Timing 834 unsigned int htotal = dst->htotal; 835 // unsigned int hblank_start = dst.hblank_start; // TODO: Remove 836 unsigned int hblank_end = dst->hblank_end; 837 unsigned int vblank_start = dst->vblank_start; 838 unsigned int vblank_end = dst->vblank_end; 839 unsigned int min_vblank = mode_lib->ip.min_vblank_lines; 840 841 double dppclk_freq_in_mhz = clks->dppclk_mhz; 842 double dispclk_freq_in_mhz = clks->dispclk_mhz; 843 double refclk_freq_in_mhz = clks->refclk_mhz; 844 double pclk_freq_in_mhz = dst->pixel_rate_mhz; 845 bool interlaced = dst->interlaced; 846 847 double ref_freq_to_pix_freq = refclk_freq_in_mhz / pclk_freq_in_mhz; 848 849 double min_dcfclk_mhz; 850 double t_calc_us; 851 double min_ttu_vblank; 852 853 double min_dst_y_ttu_vblank; 854 unsigned int dlg_vblank_start; 855 bool dual_plane; 856 bool mode_422; 857 unsigned int access_dir; 858 unsigned int vp_height_l; 859 unsigned int vp_width_l; 860 unsigned int vp_height_c; 861 unsigned int vp_width_c; 862 863 // Scaling 864 unsigned int htaps_l; 865 unsigned int htaps_c; 866 double hratio_l; 867 double hratio_c; 868 double vratio_l; 869 double vratio_c; 870 bool scl_enable; 871 872 double line_time_in_us; 873 // double vinit_l; 874 // double vinit_c; 875 // double vinit_bot_l; 876 // double vinit_bot_c; 877 878 // unsigned int swath_height_l; 879 unsigned int swath_width_ub_l; 880 // unsigned int dpte_bytes_per_row_ub_l; 881 unsigned int dpte_groups_per_row_ub_l; 882 // unsigned int meta_pte_bytes_per_frame_ub_l; 883 // unsigned int meta_bytes_per_row_ub_l; 884 885 // unsigned int swath_height_c; 886 unsigned int swath_width_ub_c; 887 // unsigned int dpte_bytes_per_row_ub_c; 888 unsigned int dpte_groups_per_row_ub_c; 889 890 unsigned int meta_chunks_per_row_ub_l; 891 unsigned int meta_chunks_per_row_ub_c; 892 unsigned int vupdate_offset; 893 unsigned int vupdate_width; 894 unsigned int vready_offset; 895 896 unsigned int dppclk_delay_subtotal; 897 unsigned int dispclk_delay_subtotal; 898 unsigned int pixel_rate_delay_subtotal; 899 900 unsigned int vstartup_start; 901 unsigned int dst_x_after_scaler; 902 unsigned int dst_y_after_scaler; 903 double line_wait; 904 double dst_y_prefetch; 905 double dst_y_per_vm_vblank; 906 double dst_y_per_row_vblank; 907 double dst_y_per_vm_flip; 908 double dst_y_per_row_flip; 909 double max_dst_y_per_vm_vblank; 910 double max_dst_y_per_row_vblank; 911 double lsw; 912 double vratio_pre_l; 913 double vratio_pre_c; 914 unsigned int req_per_swath_ub_l; 915 unsigned int req_per_swath_ub_c; 916 unsigned int meta_row_height_l; 917 unsigned int meta_row_height_c; 918 unsigned int swath_width_pixels_ub_l; 919 unsigned int swath_width_pixels_ub_c; 920 unsigned int scaler_rec_in_width_l; 921 unsigned int scaler_rec_in_width_c; 922 unsigned int dpte_row_height_l; 923 unsigned int dpte_row_height_c; 924 double hscale_pixel_rate_l; 925 double hscale_pixel_rate_c; 926 double min_hratio_fact_l; 927 double min_hratio_fact_c; 928 double refcyc_per_line_delivery_pre_l; 929 double refcyc_per_line_delivery_pre_c; 930 double refcyc_per_line_delivery_l; 931 double refcyc_per_line_delivery_c; 932 933 double refcyc_per_req_delivery_pre_l; 934 double refcyc_per_req_delivery_pre_c; 935 double refcyc_per_req_delivery_l; 936 double refcyc_per_req_delivery_c; 937 938 unsigned int full_recout_width; 939 double refcyc_per_req_delivery_pre_cur0; 940 double refcyc_per_req_delivery_cur0; 941 double refcyc_per_req_delivery_pre_cur1; 942 double refcyc_per_req_delivery_cur1; 943 944 memset(disp_dlg_regs, 0, sizeof(*disp_dlg_regs)); 945 memset(disp_ttu_regs, 0, sizeof(*disp_ttu_regs)); 946 947 dml_print("DML_DLG: %s: cstate_en = %d\n", __func__, cstate_en); 948 dml_print("DML_DLG: %s: pstate_en = %d\n", __func__, pstate_en); 949 950 dml_print("DML_DLG: %s: dppclk_freq_in_mhz = %3.2f\n", __func__, dppclk_freq_in_mhz); 951 dml_print("DML_DLG: %s: dispclk_freq_in_mhz = %3.2f\n", __func__, dispclk_freq_in_mhz); 952 dml_print("DML_DLG: %s: refclk_freq_in_mhz = %3.2f\n", __func__, refclk_freq_in_mhz); 953 dml_print("DML_DLG: %s: pclk_freq_in_mhz = %3.2f\n", __func__, pclk_freq_in_mhz); 954 dml_print("DML_DLG: %s: interlaced = %d\n", __func__, interlaced); 955 ASSERT(ref_freq_to_pix_freq < 4.0); 956 957 disp_dlg_regs->ref_freq_to_pix_freq = 958 (unsigned int) (ref_freq_to_pix_freq * dml_pow(2, 19)); 959 disp_dlg_regs->refcyc_per_htotal = (unsigned int) (ref_freq_to_pix_freq * (double) htotal 960 * dml_pow(2, 8)); 961 disp_dlg_regs->dlg_vblank_end = interlaced ? (vblank_end / 2) : vblank_end; // 15 bits 962 disp_dlg_regs->refcyc_h_blank_end = (unsigned int) ((double) hblank_end 963 * (double) ref_freq_to_pix_freq); 964 ASSERT(disp_dlg_regs->refcyc_h_blank_end < (unsigned int)dml_pow(2, 13)); 965 966 min_dcfclk_mhz = dlg_sys_param.deepsleep_dcfclk_mhz; 967 t_calc_us = get_tcalc(mode_lib, e2e_pipe_param, num_pipes); 968 min_ttu_vblank = get_min_ttu_vblank(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 969 970 min_dst_y_ttu_vblank = min_ttu_vblank * pclk_freq_in_mhz / (double) htotal; 971 dlg_vblank_start = interlaced ? (vblank_start / 2) : vblank_start; 972 973 disp_dlg_regs->min_dst_y_next_start = (unsigned int) (((double) dlg_vblank_start) * dml_pow(2, 2)); 974 ASSERT(disp_dlg_regs->min_dst_y_next_start < (unsigned int)dml_pow(2, 18)); 975 976 dml_print( 977 "DML_DLG: %s: min_dcfclk_mhz = %3.2f\n", 978 __func__, 979 min_dcfclk_mhz); 980 dml_print( 981 "DML_DLG: %s: min_ttu_vblank = %3.2f\n", 982 __func__, 983 min_ttu_vblank); 984 dml_print( 985 "DML_DLG: %s: min_dst_y_ttu_vblank = %3.2f\n", 986 __func__, 987 min_dst_y_ttu_vblank); 988 dml_print( 989 "DML_DLG: %s: t_calc_us = %3.2f\n", 990 __func__, 991 t_calc_us); 992 dml_print( 993 "DML_DLG: %s: disp_dlg_regs->min_dst_y_next_start = 0x%0x\n", 994 __func__, 995 disp_dlg_regs->min_dst_y_next_start); 996 dml_print( 997 "DML_DLG: %s: ref_freq_to_pix_freq = %3.2f\n", 998 __func__, 999 ref_freq_to_pix_freq); 1000 1001 // ------------------------- 1002 // Section 1.15.2.2: Prefetch, Active and TTU 1003 // ------------------------- 1004 // Prefetch Calc 1005 // Source 1006 // dcc_en = src.dcc; 1007 dual_plane = is_dual_plane((enum source_format_class) (src->source_format)); 1008 mode_422 = false; // FIXME 1009 access_dir = (src->source_scan == dm_vert); // vp access direction: horizontal or vertical accessed 1010 // bytes_per_element_l = get_bytes_per_element(source_format_class(src.source_format), 0); 1011 // bytes_per_element_c = get_bytes_per_element(source_format_class(src.source_format), 1); 1012 vp_height_l = src->viewport_height; 1013 vp_width_l = src->viewport_width; 1014 vp_height_c = src->viewport_height_c; 1015 vp_width_c = src->viewport_width_c; 1016 1017 // Scaling 1018 htaps_l = taps->htaps; 1019 htaps_c = taps->htaps_c; 1020 hratio_l = scl->hscl_ratio; 1021 hratio_c = scl->hscl_ratio_c; 1022 vratio_l = scl->vscl_ratio; 1023 vratio_c = scl->vscl_ratio_c; 1024 scl_enable = scl->scl_enable; 1025 1026 line_time_in_us = (htotal / pclk_freq_in_mhz); 1027 swath_width_ub_l = rq_dlg_param.rq_l.swath_width_ub; 1028 dpte_groups_per_row_ub_l = rq_dlg_param.rq_l.dpte_groups_per_row_ub; 1029 swath_width_ub_c = rq_dlg_param.rq_c.swath_width_ub; 1030 dpte_groups_per_row_ub_c = rq_dlg_param.rq_c.dpte_groups_per_row_ub; 1031 1032 meta_chunks_per_row_ub_l = rq_dlg_param.rq_l.meta_chunks_per_row_ub; 1033 meta_chunks_per_row_ub_c = rq_dlg_param.rq_c.meta_chunks_per_row_ub; 1034 vupdate_offset = dst->vupdate_offset; 1035 vupdate_width = dst->vupdate_width; 1036 vready_offset = dst->vready_offset; 1037 1038 dppclk_delay_subtotal = mode_lib->ip.dppclk_delay_subtotal; 1039 dispclk_delay_subtotal = mode_lib->ip.dispclk_delay_subtotal; 1040 1041 if (scl_enable) 1042 dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_scl; 1043 else 1044 dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_scl_lb_only; 1045 1046 dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_cnvc_formatter 1047 + src->num_cursors * mode_lib->ip.dppclk_delay_cnvc_cursor; 1048 1049 if (dout->dsc_enable) { 1050 double dsc_delay = get_dsc_delay(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1051 1052 dispclk_delay_subtotal += dsc_delay; 1053 } 1054 1055 pixel_rate_delay_subtotal = dppclk_delay_subtotal * pclk_freq_in_mhz / dppclk_freq_in_mhz 1056 + dispclk_delay_subtotal * pclk_freq_in_mhz / dispclk_freq_in_mhz; 1057 1058 vstartup_start = dst->vstartup_start; 1059 if (interlaced) { 1060 if (vstartup_start / 2.0 1061 - (double) (vready_offset + vupdate_width + vupdate_offset) / htotal 1062 <= vblank_end / 2.0) 1063 disp_dlg_regs->vready_after_vcount0 = 1; 1064 else 1065 disp_dlg_regs->vready_after_vcount0 = 0; 1066 } else { 1067 if (vstartup_start 1068 - (double) (vready_offset + vupdate_width + vupdate_offset) / htotal 1069 <= vblank_end) 1070 disp_dlg_regs->vready_after_vcount0 = 1; 1071 else 1072 disp_dlg_regs->vready_after_vcount0 = 0; 1073 } 1074 1075 // TODO: Where is this coming from? 1076 if (interlaced) 1077 vstartup_start = vstartup_start / 2; 1078 1079 // TODO: What if this min_vblank doesn't match the value in the dml_config_settings.cpp? 1080 if (vstartup_start >= min_vblank) { 1081 dml_print( 1082 "WARNING: DML_DLG: %s: vblank_start=%d vblank_end=%d\n", 1083 __func__, 1084 vblank_start, 1085 vblank_end); 1086 dml_print( 1087 "WARNING: DML_DLG: %s: vstartup_start=%d should be less than min_vblank=%d\n", 1088 __func__, 1089 vstartup_start, 1090 min_vblank); 1091 min_vblank = vstartup_start + 1; 1092 dml_print( 1093 "WARNING: DML_DLG: %s: vstartup_start=%d should be less than min_vblank=%d\n", 1094 __func__, 1095 vstartup_start, 1096 min_vblank); 1097 } 1098 1099 dst_x_after_scaler = get_dst_x_after_scaler(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1100 dst_y_after_scaler = get_dst_y_after_scaler(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1101 1102 dml_print("DML_DLG: %s: htotal = %d\n", __func__, htotal); 1103 dml_print( 1104 "DML_DLG: %s: pixel_rate_delay_subtotal = %d\n", 1105 __func__, 1106 pixel_rate_delay_subtotal); 1107 dml_print( 1108 "DML_DLG: %s: dst_x_after_scaler = %d\n", 1109 __func__, 1110 dst_x_after_scaler); 1111 dml_print( 1112 "DML_DLG: %s: dst_y_after_scaler = %d\n", 1113 __func__, 1114 dst_y_after_scaler); 1115 1116 // Lwait 1117 // TODO: Should this be urgent_latency_pixel_mixed_with_vm_data_us? 1118 line_wait = mode_lib->soc.urgent_latency_pixel_data_only_us; 1119 if (cstate_en) 1120 line_wait = dml_max(mode_lib->soc.sr_enter_plus_exit_time_us, line_wait); 1121 if (pstate_en) 1122 line_wait = dml_max( 1123 mode_lib->soc.dram_clock_change_latency_us 1124 + mode_lib->soc.urgent_latency_pixel_data_only_us, // TODO: Should this be urgent_latency_pixel_mixed_with_vm_data_us? 1125 line_wait); 1126 line_wait = line_wait / line_time_in_us; 1127 1128 dst_y_prefetch = get_dst_y_prefetch(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1129 dml_print("DML_DLG: %s: dst_y_prefetch (after rnd) = %3.2f\n", __func__, dst_y_prefetch); 1130 1131 dst_y_per_vm_vblank = get_dst_y_per_vm_vblank( 1132 mode_lib, 1133 e2e_pipe_param, 1134 num_pipes, 1135 pipe_idx); 1136 dst_y_per_row_vblank = get_dst_y_per_row_vblank( 1137 mode_lib, 1138 e2e_pipe_param, 1139 num_pipes, 1140 pipe_idx); 1141 dst_y_per_vm_flip = get_dst_y_per_vm_flip(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1142 dst_y_per_row_flip = get_dst_y_per_row_flip(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1143 1144 max_dst_y_per_vm_vblank = 32.0; 1145 max_dst_y_per_row_vblank = 16.0; 1146 1147 // magic! 1148 if (htotal <= 75) { 1149 min_vblank = 300; 1150 max_dst_y_per_vm_vblank = 100.0; 1151 max_dst_y_per_row_vblank = 100.0; 1152 } 1153 1154 dml_print("DML_DLG: %s: dst_y_per_vm_flip = %3.2f\n", __func__, dst_y_per_vm_flip); 1155 dml_print("DML_DLG: %s: dst_y_per_row_flip = %3.2f\n", __func__, dst_y_per_row_flip); 1156 dml_print("DML_DLG: %s: dst_y_per_vm_vblank = %3.2f\n", __func__, dst_y_per_vm_vblank); 1157 dml_print("DML_DLG: %s: dst_y_per_row_vblank = %3.2f\n", __func__, dst_y_per_row_vblank); 1158 1159 ASSERT(dst_y_per_vm_vblank < max_dst_y_per_vm_vblank); 1160 ASSERT(dst_y_per_row_vblank < max_dst_y_per_row_vblank); 1161 1162 ASSERT(dst_y_prefetch > (dst_y_per_vm_vblank + dst_y_per_row_vblank)); 1163 lsw = dst_y_prefetch - (dst_y_per_vm_vblank + dst_y_per_row_vblank); 1164 1165 dml_print("DML_DLG: %s: lsw = %3.2f\n", __func__, lsw); 1166 1167 vratio_pre_l = get_vratio_prefetch_l(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1168 vratio_pre_c = get_vratio_prefetch_c(mode_lib, e2e_pipe_param, num_pipes, pipe_idx); 1169 1170 dml_print("DML_DLG: %s: vratio_pre_l=%3.2f\n", __func__, vratio_pre_l); 1171 dml_print("DML_DLG: %s: vratio_pre_c=%3.2f\n", __func__, vratio_pre_c); 1172 1173 // Active 1174 req_per_swath_ub_l = rq_dlg_param.rq_l.req_per_swath_ub; 1175 req_per_swath_ub_c = rq_dlg_param.rq_c.req_per_swath_ub; 1176 meta_row_height_l = rq_dlg_param.rq_l.meta_row_height; 1177 meta_row_height_c = rq_dlg_param.rq_c.meta_row_height; 1178 swath_width_pixels_ub_l = 0; 1179 swath_width_pixels_ub_c = 0; 1180 scaler_rec_in_width_l = 0; 1181 scaler_rec_in_width_c = 0; 1182 dpte_row_height_l = rq_dlg_param.rq_l.dpte_row_height; 1183 dpte_row_height_c = rq_dlg_param.rq_c.dpte_row_height; 1184 1185 if (mode_422) { 1186 swath_width_pixels_ub_l = swath_width_ub_l * 2; // *2 for 2 pixel per element 1187 swath_width_pixels_ub_c = swath_width_ub_c * 2; 1188 } else { 1189 swath_width_pixels_ub_l = swath_width_ub_l * 1; 1190 swath_width_pixels_ub_c = swath_width_ub_c * 1; 1191 } 1192 1193 hscale_pixel_rate_l = 0.; 1194 hscale_pixel_rate_c = 0.; 1195 min_hratio_fact_l = 1.0; 1196 min_hratio_fact_c = 1.0; 1197 1198 if (hratio_l <= 1) 1199 min_hratio_fact_l = 2.0; 1200 else if (htaps_l <= 6) { 1201 if ((hratio_l * 2.0) > 4.0) 1202 min_hratio_fact_l = 4.0; 1203 else 1204 min_hratio_fact_l = hratio_l * 2.0; 1205 } else { 1206 if (hratio_l > 4.0) 1207 min_hratio_fact_l = 4.0; 1208 else 1209 min_hratio_fact_l = hratio_l; 1210 } 1211 1212 hscale_pixel_rate_l = min_hratio_fact_l * dppclk_freq_in_mhz; 1213 1214 if (hratio_c <= 1) 1215 min_hratio_fact_c = 2.0; 1216 else if (htaps_c <= 6) { 1217 if ((hratio_c * 2.0) > 4.0) 1218 min_hratio_fact_c = 4.0; 1219 else 1220 min_hratio_fact_c = hratio_c * 2.0; 1221 } else { 1222 if (hratio_c > 4.0) 1223 min_hratio_fact_c = 4.0; 1224 else 1225 min_hratio_fact_c = hratio_c; 1226 } 1227 1228 hscale_pixel_rate_c = min_hratio_fact_c * dppclk_freq_in_mhz; 1229 1230 refcyc_per_line_delivery_pre_l = 0.; 1231 refcyc_per_line_delivery_pre_c = 0.; 1232 refcyc_per_line_delivery_l = 0.; 1233 refcyc_per_line_delivery_c = 0.; 1234 1235 refcyc_per_req_delivery_pre_l = 0.; 1236 refcyc_per_req_delivery_pre_c = 0.; 1237 refcyc_per_req_delivery_l = 0.; 1238 refcyc_per_req_delivery_c = 0.; 1239 1240 full_recout_width = 0; 1241 // In ODM 1242 if (src->is_hsplit) { 1243 // This "hack" is only allowed (and valid) for MPC combine. In ODM 1244 // combine, you MUST specify the full_recout_width...according to Oswin 1245 if (dst->full_recout_width == 0 && !dst->odm_combine) { 1246 dml_print( 1247 "DML_DLG: %s: Warning: full_recout_width not set in hsplit mode\n", 1248 __func__); 1249 full_recout_width = dst->recout_width * 2; // assume half split for dcn1 1250 } else 1251 full_recout_width = dst->full_recout_width; 1252 } else 1253 full_recout_width = dst->recout_width; 1254 1255 // As of DCN2, mpc_combine and odm_combine are mutually exclusive 1256 refcyc_per_line_delivery_pre_l = get_refcyc_per_delivery( 1257 mode_lib, 1258 refclk_freq_in_mhz, 1259 pclk_freq_in_mhz, 1260 dst->odm_combine, 1261 full_recout_width, 1262 dst->hactive, 1263 vratio_pre_l, 1264 hscale_pixel_rate_l, 1265 swath_width_pixels_ub_l, 1266 1); // per line 1267 1268 refcyc_per_line_delivery_l = get_refcyc_per_delivery( 1269 mode_lib, 1270 refclk_freq_in_mhz, 1271 pclk_freq_in_mhz, 1272 dst->odm_combine, 1273 full_recout_width, 1274 dst->hactive, 1275 vratio_l, 1276 hscale_pixel_rate_l, 1277 swath_width_pixels_ub_l, 1278 1); // per line 1279 1280 dml_print("DML_DLG: %s: full_recout_width = %d\n", __func__, full_recout_width); 1281 dml_print( 1282 "DML_DLG: %s: hscale_pixel_rate_l = %3.2f\n", 1283 __func__, 1284 hscale_pixel_rate_l); 1285 dml_print( 1286 "DML_DLG: %s: refcyc_per_line_delivery_pre_l = %3.2f\n", 1287 __func__, 1288 refcyc_per_line_delivery_pre_l); 1289 dml_print( 1290 "DML_DLG: %s: refcyc_per_line_delivery_l = %3.2f\n", 1291 __func__, 1292 refcyc_per_line_delivery_l); 1293 1294 if (dual_plane) { 1295 refcyc_per_line_delivery_pre_c = get_refcyc_per_delivery( 1296 mode_lib, 1297 refclk_freq_in_mhz, 1298 pclk_freq_in_mhz, 1299 dst->odm_combine, 1300 full_recout_width, 1301 dst->hactive, 1302 vratio_pre_c, 1303 hscale_pixel_rate_c, 1304 swath_width_pixels_ub_c, 1305 1); // per line 1306 1307 refcyc_per_line_delivery_c = get_refcyc_per_delivery( 1308 mode_lib, 1309 refclk_freq_in_mhz, 1310 pclk_freq_in_mhz, 1311 dst->odm_combine, 1312 full_recout_width, 1313 dst->hactive, 1314 vratio_c, 1315 hscale_pixel_rate_c, 1316 swath_width_pixels_ub_c, 1317 1); // per line 1318 1319 dml_print( 1320 "DML_DLG: %s: refcyc_per_line_delivery_pre_c = %3.2f\n", 1321 __func__, 1322 refcyc_per_line_delivery_pre_c); 1323 dml_print( 1324 "DML_DLG: %s: refcyc_per_line_delivery_c = %3.2f\n", 1325 __func__, 1326 refcyc_per_line_delivery_c); 1327 } 1328 1329 // TTU - Luma / Chroma 1330 if (access_dir) { // vertical access 1331 scaler_rec_in_width_l = vp_height_l; 1332 scaler_rec_in_width_c = vp_height_c; 1333 } else { 1334 scaler_rec_in_width_l = vp_width_l; 1335 scaler_rec_in_width_c = vp_width_c; 1336 } 1337 1338 refcyc_per_req_delivery_pre_l = get_refcyc_per_delivery( 1339 mode_lib, 1340 refclk_freq_in_mhz, 1341 pclk_freq_in_mhz, 1342 dst->odm_combine, 1343 full_recout_width, 1344 dst->hactive, 1345 vratio_pre_l, 1346 hscale_pixel_rate_l, 1347 scaler_rec_in_width_l, 1348 req_per_swath_ub_l); // per req 1349 refcyc_per_req_delivery_l = get_refcyc_per_delivery( 1350 mode_lib, 1351 refclk_freq_in_mhz, 1352 pclk_freq_in_mhz, 1353 dst->odm_combine, 1354 full_recout_width, 1355 dst->hactive, 1356 vratio_l, 1357 hscale_pixel_rate_l, 1358 scaler_rec_in_width_l, 1359 req_per_swath_ub_l); // per req 1360 1361 dml_print( 1362 "DML_DLG: %s: refcyc_per_req_delivery_pre_l = %3.2f\n", 1363 __func__, 1364 refcyc_per_req_delivery_pre_l); 1365 dml_print( 1366 "DML_DLG: %s: refcyc_per_req_delivery_l = %3.2f\n", 1367 __func__, 1368 refcyc_per_req_delivery_l); 1369 1370 ASSERT(refcyc_per_req_delivery_pre_l < dml_pow(2, 13)); 1371 ASSERT(refcyc_per_req_delivery_l < dml_pow(2, 13)); 1372 1373 if (dual_plane) { 1374 refcyc_per_req_delivery_pre_c = get_refcyc_per_delivery( 1375 mode_lib, 1376 refclk_freq_in_mhz, 1377 pclk_freq_in_mhz, 1378 dst->odm_combine, 1379 full_recout_width, 1380 dst->hactive, 1381 vratio_pre_c, 1382 hscale_pixel_rate_c, 1383 scaler_rec_in_width_c, 1384 req_per_swath_ub_c); // per req 1385 refcyc_per_req_delivery_c = get_refcyc_per_delivery( 1386 mode_lib, 1387 refclk_freq_in_mhz, 1388 pclk_freq_in_mhz, 1389 dst->odm_combine, 1390 full_recout_width, 1391 dst->hactive, 1392 vratio_c, 1393 hscale_pixel_rate_c, 1394 scaler_rec_in_width_c, 1395 req_per_swath_ub_c); // per req 1396 1397 dml_print( 1398 "DML_DLG: %s: refcyc_per_req_delivery_pre_c = %3.2f\n", 1399 __func__, 1400 refcyc_per_req_delivery_pre_c); 1401 dml_print( 1402 "DML_DLG: %s: refcyc_per_req_delivery_c = %3.2f\n", 1403 __func__, 1404 refcyc_per_req_delivery_c); 1405 1406 ASSERT(refcyc_per_req_delivery_pre_c < dml_pow(2, 13)); 1407 ASSERT(refcyc_per_req_delivery_c < dml_pow(2, 13)); 1408 } 1409 1410 // TTU - Cursor 1411 refcyc_per_req_delivery_pre_cur0 = 0.0; 1412 refcyc_per_req_delivery_cur0 = 0.0; 1413 if (src->num_cursors > 0) { 1414 calculate_ttu_cursor( 1415 mode_lib, 1416 &refcyc_per_req_delivery_pre_cur0, 1417 &refcyc_per_req_delivery_cur0, 1418 refclk_freq_in_mhz, 1419 ref_freq_to_pix_freq, 1420 hscale_pixel_rate_l, 1421 scl->hscl_ratio, 1422 vratio_pre_l, 1423 vratio_l, 1424 src->cur0_src_width, 1425 (enum cursor_bpp) (src->cur0_bpp)); 1426 } 1427 1428 refcyc_per_req_delivery_pre_cur1 = 0.0; 1429 refcyc_per_req_delivery_cur1 = 0.0; 1430 if (src->num_cursors > 1) { 1431 calculate_ttu_cursor( 1432 mode_lib, 1433 &refcyc_per_req_delivery_pre_cur1, 1434 &refcyc_per_req_delivery_cur1, 1435 refclk_freq_in_mhz, 1436 ref_freq_to_pix_freq, 1437 hscale_pixel_rate_l, 1438 scl->hscl_ratio, 1439 vratio_pre_l, 1440 vratio_l, 1441 src->cur1_src_width, 1442 (enum cursor_bpp) (src->cur1_bpp)); 1443 } 1444 1445 // TTU - Misc 1446 // all hard-coded 1447 1448 // Assignment to register structures 1449 disp_dlg_regs->dst_y_after_scaler = dst_y_after_scaler; // in terms of line 1450 disp_dlg_regs->refcyc_x_after_scaler = dst_x_after_scaler * ref_freq_to_pix_freq; // in terms of refclk 1451 ASSERT(disp_dlg_regs->refcyc_x_after_scaler < (unsigned int)dml_pow(2, 13)); 1452 disp_dlg_regs->dst_y_prefetch = (unsigned int) (dst_y_prefetch * dml_pow(2, 2)); 1453 disp_dlg_regs->dst_y_per_vm_vblank = (unsigned int) (dst_y_per_vm_vblank * dml_pow(2, 2)); 1454 disp_dlg_regs->dst_y_per_row_vblank = (unsigned int) (dst_y_per_row_vblank * dml_pow(2, 2)); 1455 disp_dlg_regs->dst_y_per_vm_flip = (unsigned int) (dst_y_per_vm_flip * dml_pow(2, 2)); 1456 disp_dlg_regs->dst_y_per_row_flip = (unsigned int) (dst_y_per_row_flip * dml_pow(2, 2)); 1457 1458 disp_dlg_regs->vratio_prefetch = (unsigned int) (vratio_pre_l * dml_pow(2, 19)); 1459 disp_dlg_regs->vratio_prefetch_c = (unsigned int) (vratio_pre_c * dml_pow(2, 19)); 1460 1461 dml_print("DML_DLG: %s: disp_dlg_regs->dst_y_per_vm_vblank = 0x%x\n", __func__, disp_dlg_regs->dst_y_per_vm_vblank); 1462 dml_print("DML_DLG: %s: disp_dlg_regs->dst_y_per_row_vblank = 0x%x\n", __func__, disp_dlg_regs->dst_y_per_row_vblank); 1463 dml_print("DML_DLG: %s: disp_dlg_regs->dst_y_per_vm_flip = 0x%x\n", __func__, disp_dlg_regs->dst_y_per_vm_flip); 1464 dml_print("DML_DLG: %s: disp_dlg_regs->dst_y_per_row_flip = 0x%x\n", __func__, disp_dlg_regs->dst_y_per_row_flip); 1465 1466 disp_dlg_regs->refcyc_per_pte_group_vblank_l = 1467 (unsigned int) (dst_y_per_row_vblank * (double) htotal 1468 * ref_freq_to_pix_freq / (double) dpte_groups_per_row_ub_l); 1469 if ((refclk_freq_in_mhz / ref_freq_to_pix_freq < 28) && 1470 disp_dlg_regs->refcyc_per_pte_group_vblank_l >= (unsigned int)dml_pow(2, 13)) 1471 disp_dlg_regs->refcyc_per_pte_group_vblank_l = (1 << 13) - 1; 1472 else 1473 ASSERT(disp_dlg_regs->refcyc_per_pte_group_vblank_l < (unsigned int)dml_pow(2, 13)); 1474 1475 if (dual_plane) { 1476 disp_dlg_regs->refcyc_per_pte_group_vblank_c = (unsigned int) (dst_y_per_row_vblank 1477 * (double) htotal * ref_freq_to_pix_freq 1478 / (double) dpte_groups_per_row_ub_c); 1479 if ((refclk_freq_in_mhz / ref_freq_to_pix_freq < 28) && 1480 disp_dlg_regs->refcyc_per_pte_group_vblank_c >= (unsigned int)dml_pow(2, 13)) 1481 disp_dlg_regs->refcyc_per_pte_group_vblank_c = (1 << 13) - 1; 1482 else 1483 ASSERT(disp_dlg_regs->refcyc_per_pte_group_vblank_c 1484 < (unsigned int)dml_pow(2, 13)); 1485 } 1486 1487 if (src->dcc) 1488 disp_dlg_regs->refcyc_per_meta_chunk_vblank_l = 1489 (unsigned int) (dst_y_per_row_vblank * (double) htotal 1490 * ref_freq_to_pix_freq / (double) meta_chunks_per_row_ub_l); 1491 else 1492 disp_dlg_regs->refcyc_per_meta_chunk_vblank_l = 0; 1493 ASSERT(disp_dlg_regs->refcyc_per_meta_chunk_vblank_l < (unsigned int)dml_pow(2, 13)); 1494 1495 disp_dlg_regs->refcyc_per_meta_chunk_vblank_c = 1496 disp_dlg_regs->refcyc_per_meta_chunk_vblank_l; // dcc for 4:2:0 is not supported in dcn1.0. assigned to be the same as _l for now 1497 1498 disp_dlg_regs->refcyc_per_pte_group_flip_l = (unsigned int) (dst_y_per_row_flip * htotal 1499 * ref_freq_to_pix_freq) / dpte_groups_per_row_ub_l; 1500 disp_dlg_regs->refcyc_per_meta_chunk_flip_l = (unsigned int) (dst_y_per_row_flip * htotal 1501 * ref_freq_to_pix_freq) / meta_chunks_per_row_ub_l; 1502 1503 if (dual_plane) { 1504 disp_dlg_regs->refcyc_per_pte_group_flip_c = (unsigned int) (dst_y_per_row_flip 1505 * htotal * ref_freq_to_pix_freq) / dpte_groups_per_row_ub_c; 1506 disp_dlg_regs->refcyc_per_meta_chunk_flip_c = (unsigned int) (dst_y_per_row_flip 1507 * htotal * ref_freq_to_pix_freq) / meta_chunks_per_row_ub_c; 1508 } 1509 1510 disp_dlg_regs->refcyc_per_vm_group_vblank = get_refcyc_per_vm_group_vblank(mode_lib, e2e_pipe_param, num_pipes, pipe_idx) * refclk_freq_in_mhz; 1511 disp_dlg_regs->refcyc_per_vm_group_flip = get_refcyc_per_vm_group_flip(mode_lib, e2e_pipe_param, num_pipes, pipe_idx) * refclk_freq_in_mhz; 1512 disp_dlg_regs->refcyc_per_vm_req_vblank = get_refcyc_per_vm_req_vblank(mode_lib, e2e_pipe_param, num_pipes, pipe_idx) * refclk_freq_in_mhz * dml_pow(2, 10); 1513 disp_dlg_regs->refcyc_per_vm_req_flip = get_refcyc_per_vm_req_flip(mode_lib, e2e_pipe_param, num_pipes, pipe_idx) * refclk_freq_in_mhz * dml_pow(2, 10); 1514 1515 // Clamp to max for now 1516 if (disp_dlg_regs->refcyc_per_vm_group_vblank >= (unsigned int)dml_pow(2, 23)) 1517 disp_dlg_regs->refcyc_per_vm_group_vblank = dml_pow(2, 23) - 1; 1518 1519 if (disp_dlg_regs->refcyc_per_vm_group_flip >= (unsigned int)dml_pow(2, 23)) 1520 disp_dlg_regs->refcyc_per_vm_group_flip = dml_pow(2, 23) - 1; 1521 1522 if (disp_dlg_regs->refcyc_per_vm_req_vblank >= (unsigned int)dml_pow(2, 23)) 1523 disp_dlg_regs->refcyc_per_vm_req_vblank = dml_pow(2, 23) - 1; 1524 1525 if (disp_dlg_regs->refcyc_per_vm_req_flip >= (unsigned int)dml_pow(2, 23)) 1526 disp_dlg_regs->refcyc_per_vm_req_flip = dml_pow(2, 23) - 1; 1527 disp_dlg_regs->dst_y_per_pte_row_nom_l = (unsigned int) ((double) dpte_row_height_l 1528 / (double) vratio_l * dml_pow(2, 2)); 1529 ASSERT(disp_dlg_regs->dst_y_per_pte_row_nom_l < (unsigned int)dml_pow(2, 17)); 1530 1531 if (dual_plane) { 1532 disp_dlg_regs->dst_y_per_pte_row_nom_c = (unsigned int) ((double) dpte_row_height_c 1533 / (double) vratio_c * dml_pow(2, 2)); 1534 if (disp_dlg_regs->dst_y_per_pte_row_nom_c >= (unsigned int) dml_pow(2, 17)) { 1535 dml_print( 1536 "DML_DLG: %s: Warning dst_y_per_pte_row_nom_c %u larger than supported by register format U15.2 %u\n", 1537 __func__, 1538 disp_dlg_regs->dst_y_per_pte_row_nom_c, 1539 (unsigned int)dml_pow(2, 17) - 1); 1540 } 1541 } 1542 1543 disp_dlg_regs->dst_y_per_meta_row_nom_l = (unsigned int) ((double) meta_row_height_l 1544 / (double) vratio_l * dml_pow(2, 2)); 1545 ASSERT(disp_dlg_regs->dst_y_per_meta_row_nom_l < (unsigned int)dml_pow(2, 17)); 1546 1547 disp_dlg_regs->dst_y_per_meta_row_nom_c = disp_dlg_regs->dst_y_per_meta_row_nom_l; // TODO: dcc for 4:2:0 is not supported in dcn1.0. assigned to be the same as _l for now 1548 1549 dml_print( 1550 "DML: Trow: %fus\n", 1551 line_time_in_us * (double)dpte_row_height_l / (double)vratio_l); 1552 1553 disp_dlg_regs->refcyc_per_pte_group_nom_l = (unsigned int) ((double) dpte_row_height_l 1554 / (double) vratio_l * (double) htotal * ref_freq_to_pix_freq 1555 / (double) dpte_groups_per_row_ub_l); 1556 if (disp_dlg_regs->refcyc_per_pte_group_nom_l >= (unsigned int) dml_pow(2, 23)) 1557 disp_dlg_regs->refcyc_per_pte_group_nom_l = dml_pow(2, 23) - 1; 1558 disp_dlg_regs->refcyc_per_meta_chunk_nom_l = (unsigned int) ((double) meta_row_height_l 1559 / (double) vratio_l * (double) htotal * ref_freq_to_pix_freq 1560 / (double) meta_chunks_per_row_ub_l); 1561 if (disp_dlg_regs->refcyc_per_meta_chunk_nom_l >= (unsigned int) dml_pow(2, 23)) 1562 disp_dlg_regs->refcyc_per_meta_chunk_nom_l = dml_pow(2, 23) - 1; 1563 1564 if (dual_plane) { 1565 disp_dlg_regs->refcyc_per_pte_group_nom_c = 1566 (unsigned int) ((double) dpte_row_height_c / (double) vratio_c 1567 * (double) htotal * ref_freq_to_pix_freq 1568 / (double) dpte_groups_per_row_ub_c); 1569 if (disp_dlg_regs->refcyc_per_pte_group_nom_c >= (unsigned int) dml_pow(2, 23)) 1570 disp_dlg_regs->refcyc_per_pte_group_nom_c = dml_pow(2, 23) - 1; 1571 1572 // TODO: Is this the right calculation? Does htotal need to be halved? 1573 disp_dlg_regs->refcyc_per_meta_chunk_nom_c = 1574 (unsigned int) ((double) meta_row_height_c / (double) vratio_c 1575 * (double) htotal * ref_freq_to_pix_freq 1576 / (double) meta_chunks_per_row_ub_c); 1577 if (disp_dlg_regs->refcyc_per_meta_chunk_nom_c >= (unsigned int) dml_pow(2, 23)) 1578 disp_dlg_regs->refcyc_per_meta_chunk_nom_c = dml_pow(2, 23) - 1; 1579 } 1580 1581 disp_dlg_regs->refcyc_per_line_delivery_pre_l = (unsigned int) dml_floor( 1582 refcyc_per_line_delivery_pre_l, 1); 1583 disp_dlg_regs->refcyc_per_line_delivery_l = (unsigned int) dml_floor( 1584 refcyc_per_line_delivery_l, 1); 1585 ASSERT(disp_dlg_regs->refcyc_per_line_delivery_pre_l < (unsigned int)dml_pow(2, 13)); 1586 ASSERT(disp_dlg_regs->refcyc_per_line_delivery_l < (unsigned int)dml_pow(2, 13)); 1587 1588 disp_dlg_regs->refcyc_per_line_delivery_pre_c = (unsigned int) dml_floor( 1589 refcyc_per_line_delivery_pre_c, 1); 1590 disp_dlg_regs->refcyc_per_line_delivery_c = (unsigned int) dml_floor( 1591 refcyc_per_line_delivery_c, 1); 1592 ASSERT(disp_dlg_regs->refcyc_per_line_delivery_pre_c < (unsigned int)dml_pow(2, 13)); 1593 ASSERT(disp_dlg_regs->refcyc_per_line_delivery_c < (unsigned int)dml_pow(2, 13)); 1594 1595 disp_dlg_regs->chunk_hdl_adjust_cur0 = 3; 1596 disp_dlg_regs->dst_y_offset_cur0 = 0; 1597 disp_dlg_regs->chunk_hdl_adjust_cur1 = 3; 1598 disp_dlg_regs->dst_y_offset_cur1 = 0; 1599 1600 disp_dlg_regs->dst_y_delta_drq_limit = 0x7fff; // off 1601 1602 disp_ttu_regs->refcyc_per_req_delivery_pre_l = (unsigned int) (refcyc_per_req_delivery_pre_l 1603 * dml_pow(2, 10)); 1604 disp_ttu_regs->refcyc_per_req_delivery_l = (unsigned int) (refcyc_per_req_delivery_l 1605 * dml_pow(2, 10)); 1606 disp_ttu_regs->refcyc_per_req_delivery_pre_c = (unsigned int) (refcyc_per_req_delivery_pre_c 1607 * dml_pow(2, 10)); 1608 disp_ttu_regs->refcyc_per_req_delivery_c = (unsigned int) (refcyc_per_req_delivery_c 1609 * dml_pow(2, 10)); 1610 disp_ttu_regs->refcyc_per_req_delivery_pre_cur0 = 1611 (unsigned int) (refcyc_per_req_delivery_pre_cur0 * dml_pow(2, 10)); 1612 disp_ttu_regs->refcyc_per_req_delivery_cur0 = (unsigned int) (refcyc_per_req_delivery_cur0 1613 * dml_pow(2, 10)); 1614 disp_ttu_regs->refcyc_per_req_delivery_pre_cur1 = 1615 (unsigned int) (refcyc_per_req_delivery_pre_cur1 * dml_pow(2, 10)); 1616 disp_ttu_regs->refcyc_per_req_delivery_cur1 = (unsigned int) (refcyc_per_req_delivery_cur1 1617 * dml_pow(2, 10)); 1618 disp_ttu_regs->qos_level_low_wm = 0; 1619 ASSERT(disp_ttu_regs->qos_level_low_wm < dml_pow(2, 14)); 1620 disp_ttu_regs->qos_level_high_wm = (unsigned int) (4.0 * (double) htotal 1621 * ref_freq_to_pix_freq); 1622 ASSERT(disp_ttu_regs->qos_level_high_wm < dml_pow(2, 14)); 1623 1624 disp_ttu_regs->qos_level_flip = 14; 1625 disp_ttu_regs->qos_level_fixed_l = 8; 1626 disp_ttu_regs->qos_level_fixed_c = 8; 1627 disp_ttu_regs->qos_level_fixed_cur0 = 8; 1628 disp_ttu_regs->qos_ramp_disable_l = 0; 1629 disp_ttu_regs->qos_ramp_disable_c = 0; 1630 disp_ttu_regs->qos_ramp_disable_cur0 = 0; 1631 1632 disp_ttu_regs->min_ttu_vblank = min_ttu_vblank * refclk_freq_in_mhz; 1633 ASSERT(disp_ttu_regs->min_ttu_vblank < dml_pow(2, 24)); 1634 1635 print__ttu_regs_st(mode_lib, *disp_ttu_regs); 1636 print__dlg_regs_st(mode_lib, *disp_dlg_regs); 1637 } 1638 1639 void dml21_rq_dlg_get_dlg_reg( 1640 struct display_mode_lib *mode_lib, 1641 display_dlg_regs_st *dlg_regs, 1642 display_ttu_regs_st *ttu_regs, 1643 display_e2e_pipe_params_st *e2e_pipe_param, 1644 const unsigned int num_pipes, 1645 const unsigned int pipe_idx, 1646 const bool cstate_en, 1647 const bool pstate_en, 1648 const bool vm_en, 1649 const bool ignore_viewport_pos, 1650 const bool immediate_flip_support) 1651 { 1652 display_rq_params_st rq_param = {0}; 1653 display_dlg_sys_params_st dlg_sys_param = {0}; 1654 1655 // Get watermark and Tex. 1656 dlg_sys_param.t_urg_wm_us = get_wm_urgent(mode_lib, e2e_pipe_param, num_pipes); 1657 dlg_sys_param.deepsleep_dcfclk_mhz = get_clk_dcf_deepsleep( 1658 mode_lib, 1659 e2e_pipe_param, 1660 num_pipes); 1661 dlg_sys_param.t_extra_us = get_urgent_extra_latency(mode_lib, e2e_pipe_param, num_pipes); 1662 dlg_sys_param.mem_trip_us = get_wm_memory_trip(mode_lib, e2e_pipe_param, num_pipes); 1663 dlg_sys_param.t_mclk_wm_us = get_wm_dram_clock_change(mode_lib, e2e_pipe_param, num_pipes); 1664 dlg_sys_param.t_sr_wm_us = get_wm_stutter_enter_exit(mode_lib, e2e_pipe_param, num_pipes); 1665 dlg_sys_param.total_flip_bw = get_total_immediate_flip_bw( 1666 mode_lib, 1667 e2e_pipe_param, 1668 num_pipes); 1669 dlg_sys_param.total_flip_bytes = get_total_immediate_flip_bytes( 1670 mode_lib, 1671 e2e_pipe_param, 1672 num_pipes); 1673 dlg_sys_param.t_srx_delay_us = mode_lib->ip.dcfclk_cstate_latency 1674 / dlg_sys_param.deepsleep_dcfclk_mhz; // TODO: Deprecated 1675 1676 print__dlg_sys_params_st(mode_lib, dlg_sys_param); 1677 1678 // system parameter calculation done 1679 1680 dml_print("DML_DLG: Calculation for pipe[%d] start\n\n", pipe_idx); 1681 dml_rq_dlg_get_rq_params(mode_lib, &rq_param, e2e_pipe_param[pipe_idx].pipe); 1682 dml_rq_dlg_get_dlg_params( 1683 mode_lib, 1684 e2e_pipe_param, 1685 num_pipes, 1686 pipe_idx, 1687 dlg_regs, 1688 ttu_regs, 1689 rq_param.dlg, 1690 dlg_sys_param, 1691 cstate_en, 1692 pstate_en); 1693 dml_print("DML_DLG: Calculation for pipe[%d] end\n", pipe_idx); 1694 } 1695 1696 void dml_rq_dlg_get_arb_params(struct display_mode_lib *mode_lib, display_arb_params_st *arb_param) 1697 { 1698 memset(arb_param, 0, sizeof(*arb_param)); 1699 arb_param->max_req_outstanding = 256; 1700 arb_param->min_req_outstanding = 68; 1701 arb_param->sat_level_us = 60; 1702 } 1703 1704 static void calculate_ttu_cursor( 1705 struct display_mode_lib *mode_lib, 1706 double *refcyc_per_req_delivery_pre_cur, 1707 double *refcyc_per_req_delivery_cur, 1708 double refclk_freq_in_mhz, 1709 double ref_freq_to_pix_freq, 1710 double hscale_pixel_rate_l, 1711 double hscl_ratio, 1712 double vratio_pre_l, 1713 double vratio_l, 1714 unsigned int cur_width, 1715 enum cursor_bpp cur_bpp) 1716 { 1717 unsigned int cur_src_width = cur_width; 1718 unsigned int cur_req_size = 0; 1719 unsigned int cur_req_width = 0; 1720 double cur_width_ub = 0.0; 1721 double cur_req_per_width = 0.0; 1722 double hactive_cur = 0.0; 1723 1724 ASSERT(cur_src_width <= 256); 1725 1726 *refcyc_per_req_delivery_pre_cur = 0.0; 1727 *refcyc_per_req_delivery_cur = 0.0; 1728 if (cur_src_width > 0) { 1729 unsigned int cur_bit_per_pixel = 0; 1730 1731 if (cur_bpp == dm_cur_2bit) { 1732 cur_req_size = 64; // byte 1733 cur_bit_per_pixel = 2; 1734 } else { // 32bit 1735 cur_bit_per_pixel = 32; 1736 if (cur_src_width >= 1 && cur_src_width <= 16) 1737 cur_req_size = 64; 1738 else if (cur_src_width >= 17 && cur_src_width <= 31) 1739 cur_req_size = 128; 1740 else 1741 cur_req_size = 256; 1742 } 1743 1744 cur_req_width = (double) cur_req_size / ((double) cur_bit_per_pixel / 8.0); 1745 cur_width_ub = dml_ceil((double) cur_src_width / (double) cur_req_width, 1) 1746 * (double) cur_req_width; 1747 cur_req_per_width = cur_width_ub / (double) cur_req_width; 1748 hactive_cur = (double) cur_src_width / hscl_ratio; // FIXME: oswin to think about what to do for cursor 1749 1750 if (vratio_pre_l <= 1.0) { 1751 *refcyc_per_req_delivery_pre_cur = hactive_cur * ref_freq_to_pix_freq 1752 / (double) cur_req_per_width; 1753 } else { 1754 *refcyc_per_req_delivery_pre_cur = (double) refclk_freq_in_mhz 1755 * (double) cur_src_width / hscale_pixel_rate_l 1756 / (double) cur_req_per_width; 1757 } 1758 1759 ASSERT(*refcyc_per_req_delivery_pre_cur < dml_pow(2, 13)); 1760 1761 if (vratio_l <= 1.0) { 1762 *refcyc_per_req_delivery_cur = hactive_cur * ref_freq_to_pix_freq 1763 / (double) cur_req_per_width; 1764 } else { 1765 *refcyc_per_req_delivery_cur = (double) refclk_freq_in_mhz 1766 * (double) cur_src_width / hscale_pixel_rate_l 1767 / (double) cur_req_per_width; 1768 } 1769 1770 dml_print( 1771 "DML_DLG: %s: cur_req_width = %d\n", 1772 __func__, 1773 cur_req_width); 1774 dml_print( 1775 "DML_DLG: %s: cur_width_ub = %3.2f\n", 1776 __func__, 1777 cur_width_ub); 1778 dml_print( 1779 "DML_DLG: %s: cur_req_per_width = %3.2f\n", 1780 __func__, 1781 cur_req_per_width); 1782 dml_print( 1783 "DML_DLG: %s: hactive_cur = %3.2f\n", 1784 __func__, 1785 hactive_cur); 1786 dml_print( 1787 "DML_DLG: %s: refcyc_per_req_delivery_pre_cur = %3.2f\n", 1788 __func__, 1789 *refcyc_per_req_delivery_pre_cur); 1790 dml_print( 1791 "DML_DLG: %s: refcyc_per_req_delivery_cur = %3.2f\n", 1792 __func__, 1793 *refcyc_per_req_delivery_cur); 1794 1795 ASSERT(*refcyc_per_req_delivery_cur < dml_pow(2, 13)); 1796 } 1797 } 1798 1799