1 /* $NetBSD: amdgpu_dcn_calc_auto.c,v 1.2 2021/12/18 23:45:01 riastradh Exp $ */ 2 3 /* 4 * Copyright 2017 Advanced Micro Devices, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: AMD 25 * 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_dcn_calc_auto.c,v 1.2 2021/12/18 23:45:01 riastradh Exp $"); 30 31 #include "dm_services.h" 32 #include "dcn_calc_auto.h" 33 #include "dcn_calc_math.h" 34 35 /* 36 * NOTE: 37 * This file is gcc-parseable HW gospel, coming straight from HW engineers. 38 * 39 * It doesn't adhere to Linux kernel style and sometimes will do things in odd 40 * ways. Unless there is something clearly wrong with it the code should 41 * remain as-is as it provides us with a guarantee from HW that it is correct. 42 */ 43 44 /*REVISION#250*/ 45 void scaler_settings_calculation(struct dcn_bw_internal_vars *v) 46 { 47 int k; 48 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 49 if (v->allow_different_hratio_vratio == dcn_bw_yes) { 50 if (v->source_scan[k] == dcn_bw_hor) { 51 v->h_ratio[k] = v->viewport_width[k] / v->scaler_rec_out_width[k]; 52 v->v_ratio[k] = v->viewport_height[k] / v->scaler_recout_height[k]; 53 } 54 else { 55 v->h_ratio[k] = v->viewport_height[k] / v->scaler_rec_out_width[k]; 56 v->v_ratio[k] = v->viewport_width[k] / v->scaler_recout_height[k]; 57 } 58 } 59 else { 60 if (v->source_scan[k] == dcn_bw_hor) { 61 v->h_ratio[k] =dcn_bw_max2(v->viewport_width[k] / v->scaler_rec_out_width[k], v->viewport_height[k] / v->scaler_recout_height[k]); 62 } 63 else { 64 v->h_ratio[k] =dcn_bw_max2(v->viewport_height[k] / v->scaler_rec_out_width[k], v->viewport_width[k] / v->scaler_recout_height[k]); 65 } 66 v->v_ratio[k] = v->h_ratio[k]; 67 } 68 if (v->interlace_output[k] == 1.0) { 69 v->v_ratio[k] = 2.0 * v->v_ratio[k]; 70 } 71 if (v->underscan_output[k] == 1.0) { 72 v->h_ratio[k] = v->h_ratio[k] * v->under_scan_factor; 73 v->v_ratio[k] = v->v_ratio[k] * v->under_scan_factor; 74 } 75 } 76 /*scaler taps calculation*/ 77 78 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 79 if (v->h_ratio[k] > 1.0) { 80 v->acceptable_quality_hta_ps =dcn_bw_min2(v->max_hscl_taps, 2.0 *dcn_bw_ceil2(v->h_ratio[k], 1.0)); 81 } 82 else if (v->h_ratio[k] < 1.0) { 83 v->acceptable_quality_hta_ps = 4.0; 84 } 85 else { 86 v->acceptable_quality_hta_ps = 1.0; 87 } 88 if (v->ta_pscalculation == dcn_bw_override) { 89 v->htaps[k] = v->override_hta_ps[k]; 90 } 91 else { 92 v->htaps[k] = v->acceptable_quality_hta_ps; 93 } 94 if (v->v_ratio[k] > 1.0) { 95 v->acceptable_quality_vta_ps =dcn_bw_min2(v->max_vscl_taps, 2.0 *dcn_bw_ceil2(v->v_ratio[k], 1.0)); 96 } 97 else if (v->v_ratio[k] < 1.0) { 98 v->acceptable_quality_vta_ps = 4.0; 99 } 100 else { 101 v->acceptable_quality_vta_ps = 1.0; 102 } 103 if (v->ta_pscalculation == dcn_bw_override) { 104 v->vtaps[k] = v->override_vta_ps[k]; 105 } 106 else { 107 v->vtaps[k] = v->acceptable_quality_vta_ps; 108 } 109 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16) { 110 v->vta_pschroma[k] = 0.0; 111 v->hta_pschroma[k] = 0.0; 112 } 113 else { 114 if (v->ta_pscalculation == dcn_bw_override) { 115 v->vta_pschroma[k] = v->override_vta_pschroma[k]; 116 v->hta_pschroma[k] = v->override_hta_pschroma[k]; 117 } 118 else { 119 v->vta_pschroma[k] = v->acceptable_quality_vta_ps; 120 v->hta_pschroma[k] = v->acceptable_quality_hta_ps; 121 } 122 } 123 } 124 } 125 126 void mode_support_and_system_configuration(struct dcn_bw_internal_vars *v) 127 { 128 int i; 129 int j; 130 int k; 131 /*mode support, voltage state and soc configuration*/ 132 133 /*scale ratio support check*/ 134 135 v->scale_ratio_support = dcn_bw_yes; 136 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 137 if (v->h_ratio[k] > v->max_hscl_ratio || v->v_ratio[k] > v->max_vscl_ratio || v->h_ratio[k] > v->htaps[k] || v->v_ratio[k] > v->vtaps[k] || (v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16 && (v->h_ratio[k] / 2.0 > v->hta_pschroma[k] || v->v_ratio[k] / 2.0 > v->vta_pschroma[k]))) { 138 v->scale_ratio_support = dcn_bw_no; 139 } 140 } 141 /*source format, pixel format and scan support check*/ 142 143 v->source_format_pixel_and_scan_support = dcn_bw_yes; 144 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 145 if ((v->source_surface_mode[k] == dcn_bw_sw_linear && v->source_scan[k] != dcn_bw_hor) || ((v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x || v->source_surface_mode[k] == dcn_bw_sw_var_d || v->source_surface_mode[k] == dcn_bw_sw_var_d_x) && v->source_pixel_format[k] != dcn_bw_rgb_sub_64)) { 146 v->source_format_pixel_and_scan_support = dcn_bw_no; 147 } 148 } 149 /*bandwidth support check*/ 150 151 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 152 if (v->source_scan[k] == dcn_bw_hor) { 153 v->swath_width_ysingle_dpp[k] = v->viewport_width[k]; 154 } 155 else { 156 v->swath_width_ysingle_dpp[k] = v->viewport_height[k]; 157 } 158 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 159 v->byte_per_pixel_in_dety[k] = 8.0; 160 v->byte_per_pixel_in_detc[k] = 0.0; 161 } 162 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) { 163 v->byte_per_pixel_in_dety[k] = 4.0; 164 v->byte_per_pixel_in_detc[k] = 0.0; 165 } 166 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) { 167 v->byte_per_pixel_in_dety[k] = 2.0; 168 v->byte_per_pixel_in_detc[k] = 0.0; 169 } 170 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 171 v->byte_per_pixel_in_dety[k] = 1.0; 172 v->byte_per_pixel_in_detc[k] = 2.0; 173 } 174 else { 175 v->byte_per_pixel_in_dety[k] = 4.0f / 3.0f; 176 v->byte_per_pixel_in_detc[k] = 8.0f / 3.0f; 177 } 178 } 179 v->total_read_bandwidth_consumed_gbyte_per_second = 0.0; 180 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 181 v->read_bandwidth[k] = v->swath_width_ysingle_dpp[k] * (dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) * v->v_ratio[k] +dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0 * v->v_ratio[k] / 2) / (v->htotal[k] / v->pixel_clock[k]); 182 if (v->dcc_enable[k] == dcn_bw_yes) { 183 v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256); 184 } 185 if (v->pte_enable == dcn_bw_yes && v->source_scan[k] != dcn_bw_hor && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x)) { 186 v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 64); 187 } 188 else if (v->pte_enable == dcn_bw_yes && v->source_scan[k] == dcn_bw_hor && (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32) && (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x)) { 189 v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256); 190 } 191 else if (v->pte_enable == dcn_bw_yes) { 192 v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 512); 193 } 194 v->total_read_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->read_bandwidth[k] / 1000.0; 195 } 196 v->total_write_bandwidth_consumed_gbyte_per_second = 0.0; 197 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 198 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) { 199 v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0; 200 } 201 else if (v->output[k] == dcn_bw_writeback) { 202 v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5; 203 } 204 else { 205 v->write_bandwidth[k] = 0.0; 206 } 207 v->total_write_bandwidth_consumed_gbyte_per_second = v->total_write_bandwidth_consumed_gbyte_per_second + v->write_bandwidth[k] / 1000.0; 208 } 209 v->total_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->total_write_bandwidth_consumed_gbyte_per_second; 210 v->dcc_enabled_in_any_plane = dcn_bw_no; 211 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 212 if (v->dcc_enable[k] == dcn_bw_yes) { 213 v->dcc_enabled_in_any_plane = dcn_bw_yes; 214 } 215 } 216 for (i = 0; i <= number_of_states_plus_one; i++) { 217 v->return_bw_todcn_per_state =dcn_bw_min2(v->return_bus_width * v->dcfclk_per_state[i], v->fabric_and_dram_bandwidth_per_state[i] * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0); 218 v->return_bw_per_state[i] = v->return_bw_todcn_per_state; 219 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->return_bw_todcn_per_state > v->dcfclk_per_state[i] * v->return_bus_width / 4.0) { 220 v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], v->return_bw_todcn_per_state * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bw_todcn_per_state - v->dcfclk_per_state[i] * v->return_bus_width / 4.0) + v->urgent_latency))); 221 } 222 v->critical_point = 2.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0); 223 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) { 224 v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], dcn_bw_pow(4.0 * v->return_bw_todcn_per_state * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2)); 225 } 226 v->return_bw_todcn_per_state =dcn_bw_min2(v->return_bus_width * v->dcfclk_per_state[i], v->fabric_and_dram_bandwidth_per_state[i] * 1000.0); 227 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->return_bw_todcn_per_state > v->dcfclk_per_state[i] * v->return_bus_width / 4.0) { 228 v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], v->return_bw_todcn_per_state * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bw_todcn_per_state - v->dcfclk_per_state[i] * v->return_bus_width / 4.0) + v->urgent_latency))); 229 } 230 v->critical_point = 2.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0); 231 if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) { 232 v->return_bw_per_state[i] =dcn_bw_min2(v->return_bw_per_state[i], dcn_bw_pow(4.0 * v->return_bw_todcn_per_state * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk_per_state[i] * v->urgent_latency / (v->return_bw_todcn_per_state * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2)); 233 } 234 } 235 for (i = 0; i <= number_of_states_plus_one; i++) { 236 if ((v->total_read_bandwidth_consumed_gbyte_per_second * 1000.0 <= v->return_bw_per_state[i]) && (v->total_bandwidth_consumed_gbyte_per_second * 1000.0 <= v->fabric_and_dram_bandwidth_per_state[i] * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0)) { 237 v->bandwidth_support[i] = dcn_bw_yes; 238 } 239 else { 240 v->bandwidth_support[i] = dcn_bw_no; 241 } 242 } 243 /*writeback latency support check*/ 244 245 v->writeback_latency_support = dcn_bw_yes; 246 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 247 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444 && v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0 > (v->writeback_luma_buffer_size + v->writeback_chroma_buffer_size) * 1024.0 / v->write_back_latency) { 248 v->writeback_latency_support = dcn_bw_no; 249 } 250 else if (v->output[k] == dcn_bw_writeback && v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) >dcn_bw_min2(v->writeback_luma_buffer_size, 2.0 * v->writeback_chroma_buffer_size) * 1024.0 / v->write_back_latency) { 251 v->writeback_latency_support = dcn_bw_no; 252 } 253 } 254 /*re-ordering buffer support check*/ 255 256 for (i = 0; i <= number_of_states_plus_one; i++) { 257 v->urgent_round_trip_and_out_of_order_latency_per_state[i] = (v->round_trip_ping_latency_cycles + 32.0) / v->dcfclk_per_state[i] + v->urgent_out_of_order_return_per_channel * v->number_of_channels / v->return_bw_per_state[i]; 258 if ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / v->return_bw_per_state[i] > v->urgent_round_trip_and_out_of_order_latency_per_state[i]) { 259 v->rob_support[i] = dcn_bw_yes; 260 } 261 else { 262 v->rob_support[i] = dcn_bw_no; 263 } 264 } 265 /*display io support check*/ 266 267 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 268 if (v->output[k] == dcn_bw_dp && v->dsc_capability == dcn_bw_yes) { 269 if (v->output_format[k] == dcn_bw_420) { 270 v->required_output_bw = v->pixel_clock[k] / 2.0; 271 } 272 else { 273 v->required_output_bw = v->pixel_clock[k]; 274 } 275 } 276 else if (v->output_format[k] == dcn_bw_420) { 277 v->required_output_bw = v->pixel_clock[k] * 3.0 / 2.0; 278 } 279 else { 280 v->required_output_bw = v->pixel_clock[k] * 3.0; 281 } 282 if (v->output[k] == dcn_bw_hdmi) { 283 v->required_phyclk[k] = v->required_output_bw; 284 switch (v->output_deep_color[k]) { 285 case dcn_bw_encoder_10bpc: 286 v->required_phyclk[k] = v->required_phyclk[k] * 5.0 / 4; 287 break; 288 case dcn_bw_encoder_12bpc: 289 v->required_phyclk[k] = v->required_phyclk[k] * 3.0 / 2; 290 break; 291 default: 292 break; 293 } 294 v->required_phyclk[k] = v->required_phyclk[k] / 3.0; 295 } 296 else if (v->output[k] == dcn_bw_dp) { 297 v->required_phyclk[k] = v->required_output_bw / 4.0; 298 } 299 else { 300 v->required_phyclk[k] = 0.0; 301 } 302 } 303 for (i = 0; i <= number_of_states_plus_one; i++) { 304 v->dio_support[i] = dcn_bw_yes; 305 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 306 if (v->required_phyclk[k] > v->phyclk_per_state[i] || (v->output[k] == dcn_bw_hdmi && v->required_phyclk[k] > 600.0)) { 307 v->dio_support[i] = dcn_bw_no; 308 } 309 } 310 } 311 /*total available writeback support check*/ 312 313 v->total_number_of_active_writeback = 0.0; 314 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 315 if (v->output[k] == dcn_bw_writeback) { 316 v->total_number_of_active_writeback = v->total_number_of_active_writeback + 1.0; 317 } 318 } 319 if (v->total_number_of_active_writeback <= v->max_num_writeback) { 320 v->total_available_writeback_support = dcn_bw_yes; 321 } 322 else { 323 v->total_available_writeback_support = dcn_bw_no; 324 } 325 /*maximum dispclk/dppclk support check*/ 326 327 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 328 if (v->h_ratio[k] > 1.0) { 329 v->pscl_factor[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] /dcn_bw_ceil2(v->htaps[k] / 6.0, 1.0)); 330 } 331 else { 332 v->pscl_factor[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput); 333 } 334 if (v->byte_per_pixel_in_detc[k] == 0.0) { 335 v->pscl_factor_chroma[k] = 0.0; 336 v->min_dppclk_using_single_dpp[k] = v->pixel_clock[k] *dcn_bw_max3(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_factor[k], 1.0); 337 } 338 else { 339 if (v->h_ratio[k] / 2.0 > 1.0) { 340 v->pscl_factor_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] / 2.0 /dcn_bw_ceil2(v->hta_pschroma[k] / 6.0, 1.0)); 341 } 342 else { 343 v->pscl_factor_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput); 344 } 345 v->min_dppclk_using_single_dpp[k] = v->pixel_clock[k] *dcn_bw_max5(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_factor[k], v->vta_pschroma[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k] / 2.0), v->h_ratio[k] * v->v_ratio[k] / 4.0 / v->pscl_factor_chroma[k], 1.0); 346 } 347 } 348 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 349 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) { 350 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 351 v->read256_block_height_y[k] = 1.0; 352 } 353 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 354 v->read256_block_height_y[k] = 4.0; 355 } 356 else { 357 v->read256_block_height_y[k] = 8.0; 358 } 359 v->read256_block_width_y[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->read256_block_height_y[k]; 360 v->read256_block_height_c[k] = 0.0; 361 v->read256_block_width_c[k] = 0.0; 362 } 363 else { 364 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 365 v->read256_block_height_y[k] = 1.0; 366 v->read256_block_height_c[k] = 1.0; 367 } 368 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 369 v->read256_block_height_y[k] = 16.0; 370 v->read256_block_height_c[k] = 8.0; 371 } 372 else { 373 v->read256_block_height_y[k] = 8.0; 374 v->read256_block_height_c[k] = 8.0; 375 } 376 v->read256_block_width_y[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->read256_block_height_y[k]; 377 v->read256_block_width_c[k] = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->read256_block_height_c[k]; 378 } 379 if (v->source_scan[k] == dcn_bw_hor) { 380 v->max_swath_height_y[k] = v->read256_block_height_y[k]; 381 v->max_swath_height_c[k] = v->read256_block_height_c[k]; 382 } 383 else { 384 v->max_swath_height_y[k] = v->read256_block_width_y[k]; 385 v->max_swath_height_c[k] = v->read256_block_width_c[k]; 386 } 387 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) { 388 if (v->source_surface_mode[k] == dcn_bw_sw_linear || (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_var_s || v->source_surface_mode[k] == dcn_bw_sw_var_s_x) && v->source_scan[k] == dcn_bw_hor)) { 389 v->min_swath_height_y[k] = v->max_swath_height_y[k]; 390 } 391 else { 392 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0; 393 } 394 v->min_swath_height_c[k] = v->max_swath_height_c[k]; 395 } 396 else { 397 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 398 v->min_swath_height_y[k] = v->max_swath_height_y[k]; 399 v->min_swath_height_c[k] = v->max_swath_height_c[k]; 400 } 401 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) { 402 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0; 403 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) { 404 v->min_swath_height_c[k] = v->max_swath_height_c[k]; 405 } 406 else { 407 v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0; 408 } 409 } 410 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) { 411 v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0; 412 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) { 413 v->min_swath_height_y[k] = v->max_swath_height_y[k]; 414 } 415 else { 416 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0; 417 } 418 } 419 else { 420 v->min_swath_height_y[k] = v->max_swath_height_y[k]; 421 v->min_swath_height_c[k] = v->max_swath_height_c[k]; 422 } 423 } 424 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 425 v->maximum_swath_width = 8192.0; 426 } 427 else { 428 v->maximum_swath_width = 5120.0; 429 } 430 v->number_of_dpp_required_for_det_size =dcn_bw_ceil2(v->swath_width_ysingle_dpp[k] /dcn_bw_min2(v->maximum_swath_width, v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / (v->byte_per_pixel_in_dety[k] * v->min_swath_height_y[k] + v->byte_per_pixel_in_detc[k] / 2.0 * v->min_swath_height_c[k])), 1.0); 431 if (v->byte_per_pixel_in_detc[k] == 0.0) { 432 v->number_of_dpp_required_for_lb_size =dcn_bw_ceil2((v->vtaps[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k], 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] /dcn_bw_max2(v->h_ratio[k], 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0); 433 } 434 else { 435 v->number_of_dpp_required_for_lb_size =dcn_bw_max2(dcn_bw_ceil2((v->vtaps[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k], 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] /dcn_bw_max2(v->h_ratio[k], 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0),dcn_bw_ceil2((v->vta_pschroma[k] +dcn_bw_max2(dcn_bw_ceil2(v->v_ratio[k] / 2.0, 1.0) - 2, 0.0)) * v->swath_width_ysingle_dpp[k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0) * v->lb_bit_per_pixel[k] / v->line_buffer_size, 1.0)); 436 } 437 v->number_of_dpp_required_for_det_and_lb_size[k] =dcn_bw_max2(v->number_of_dpp_required_for_det_size, v->number_of_dpp_required_for_lb_size); 438 } 439 for (i = 0; i <= number_of_states_plus_one; i++) { 440 for (j = 0; j <= 1; j++) { 441 v->total_number_of_active_dpp[i][j] = 0.0; 442 v->required_dispclk[i][j] = 0.0; 443 v->dispclk_dppclk_support[i][j] = dcn_bw_yes; 444 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 445 v->min_dispclk_using_single_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] * (j + 1)) * (1.0 + v->downspreading / 100.0); 446 if (v->odm_capability == dcn_bw_yes) { 447 v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k] / 2.0, v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0); 448 } 449 else { 450 v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0); 451 } 452 if (i < number_of_states) { 453 v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0); 454 v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0); 455 } 456 if (v->min_dispclk_using_single_dpp <=dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i]) && v->number_of_dpp_required_for_det_and_lb_size[k] <= 1.0) { 457 v->no_of_dpp[i][j][k] = 1.0; 458 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp); 459 } 460 else if (v->min_dispclk_using_dual_dpp <=dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) { 461 v->no_of_dpp[i][j][k] = 2.0; 462 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp); 463 } 464 else { 465 v->no_of_dpp[i][j][k] = 2.0; 466 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp); 467 v->dispclk_dppclk_support[i][j] = dcn_bw_no; 468 } 469 v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k]; 470 } 471 if (v->total_number_of_active_dpp[i][j] > v->max_num_dpp) { 472 v->total_number_of_active_dpp[i][j] = 0.0; 473 v->required_dispclk[i][j] = 0.0; 474 v->dispclk_dppclk_support[i][j] = dcn_bw_yes; 475 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 476 v->min_dispclk_using_single_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] * (j + 1)) * (1.0 + v->downspreading / 100.0); 477 v->min_dispclk_using_dual_dpp =dcn_bw_max2(v->pixel_clock[k], v->min_dppclk_using_single_dpp[k] / 2.0 * (j + 1)) * (1.0 + v->downspreading / 100.0); 478 if (i < number_of_states) { 479 v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0); 480 v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0); 481 } 482 if (v->number_of_dpp_required_for_det_and_lb_size[k] <= 1.0) { 483 v->no_of_dpp[i][j][k] = 1.0; 484 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp); 485 if (v->min_dispclk_using_single_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) { 486 v->dispclk_dppclk_support[i][j] = dcn_bw_no; 487 } 488 } 489 else { 490 v->no_of_dpp[i][j][k] = 2.0; 491 v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp); 492 if (v->min_dispclk_using_dual_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) { 493 v->dispclk_dppclk_support[i][j] = dcn_bw_no; 494 } 495 } 496 v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k]; 497 } 498 } 499 } 500 } 501 /*viewport size check*/ 502 503 v->viewport_size_support = dcn_bw_yes; 504 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 505 if (v->number_of_dpp_required_for_det_and_lb_size[k] > 2.0) { 506 v->viewport_size_support = dcn_bw_no; 507 } 508 } 509 /*total available pipes support check*/ 510 511 for (i = 0; i <= number_of_states_plus_one; i++) { 512 for (j = 0; j <= 1; j++) { 513 if (v->total_number_of_active_dpp[i][j] <= v->max_num_dpp) { 514 v->total_available_pipes_support[i][j] = dcn_bw_yes; 515 } 516 else { 517 v->total_available_pipes_support[i][j] = dcn_bw_no; 518 } 519 } 520 } 521 /*urgent latency support check*/ 522 523 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 524 for (i = 0; i <= number_of_states_plus_one; i++) { 525 for (j = 0; j <= 1; j++) { 526 v->swath_width_yper_state[i][j][k] = v->swath_width_ysingle_dpp[k] / v->no_of_dpp[i][j][k]; 527 v->swath_width_granularity_y = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->max_swath_height_y[k]; 528 v->rounded_up_max_swath_size_bytes_y = (dcn_bw_ceil2(v->swath_width_yper_state[i][j][k] - 1.0, v->swath_width_granularity_y) + v->swath_width_granularity_y) * v->byte_per_pixel_in_dety[k] * v->max_swath_height_y[k]; 529 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) { 530 v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256; 531 } 532 if (v->max_swath_height_c[k] > 0.0) { 533 v->swath_width_granularity_c = 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->max_swath_height_c[k]; 534 } 535 v->rounded_up_max_swath_size_bytes_c = (dcn_bw_ceil2(v->swath_width_yper_state[i][j][k] / 2.0 - 1.0, v->swath_width_granularity_c) + v->swath_width_granularity_c) * v->byte_per_pixel_in_detc[k] * v->max_swath_height_c[k]; 536 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) { 537 v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256; 538 } 539 if (v->rounded_up_max_swath_size_bytes_y + v->rounded_up_max_swath_size_bytes_c <= v->det_buffer_size_in_kbyte * 1024.0 / 2.0) { 540 v->swath_height_yper_state[i][j][k] = v->max_swath_height_y[k]; 541 v->swath_height_cper_state[i][j][k] = v->max_swath_height_c[k]; 542 } 543 else { 544 v->swath_height_yper_state[i][j][k] = v->min_swath_height_y[k]; 545 v->swath_height_cper_state[i][j][k] = v->min_swath_height_c[k]; 546 } 547 if (v->byte_per_pixel_in_detc[k] == 0.0) { 548 v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k]; 549 v->lines_in_det_chroma = 0.0; 550 } 551 else if (v->swath_height_yper_state[i][j][k] <= v->swath_height_cper_state[i][j][k]) { 552 v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k]; 553 v->lines_in_det_chroma = v->det_buffer_size_in_kbyte * 1024.0 / 2.0 / v->byte_per_pixel_in_detc[k] / (v->swath_width_yper_state[i][j][k] / 2.0); 554 } 555 else { 556 v->lines_in_det_luma = v->det_buffer_size_in_kbyte * 1024.0 * 2.0 / 3.0 / v->byte_per_pixel_in_dety[k] / v->swath_width_yper_state[i][j][k]; 557 v->lines_in_det_chroma = v->det_buffer_size_in_kbyte * 1024.0 / 3.0 / v->byte_per_pixel_in_dety[k] / (v->swath_width_yper_state[i][j][k] / 2.0); 558 } 559 v->effective_lb_latency_hiding_source_lines_luma =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_yper_state[i][j][k] /dcn_bw_max2(v->h_ratio[k], 1.0)), 1.0)) - (v->vtaps[k] - 1.0); 560 v->effective_lb_latency_hiding_source_lines_chroma =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_yper_state[i][j][k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0)), 1.0)) - (v->vta_pschroma[k] - 1.0); 561 v->effective_detlb_lines_luma =dcn_bw_floor2(v->lines_in_det_luma +dcn_bw_min2(v->lines_in_det_luma * v->required_dispclk[i][j] * v->byte_per_pixel_in_dety[k] * v->pscl_factor[k] / v->return_bw_per_state[i], v->effective_lb_latency_hiding_source_lines_luma), v->swath_height_yper_state[i][j][k]); 562 v->effective_detlb_lines_chroma =dcn_bw_floor2(v->lines_in_det_chroma +dcn_bw_min2(v->lines_in_det_chroma * v->required_dispclk[i][j] * v->byte_per_pixel_in_detc[k] * v->pscl_factor_chroma[k] / v->return_bw_per_state[i], v->effective_lb_latency_hiding_source_lines_chroma), v->swath_height_cper_state[i][j][k]); 563 if (v->byte_per_pixel_in_detc[k] == 0.0) { 564 v->urgent_latency_support_us_per_state[i][j][k] = v->effective_detlb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_detlb_lines_luma * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k]); 565 } 566 else { 567 v->urgent_latency_support_us_per_state[i][j][k] =dcn_bw_min2(v->effective_detlb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_detlb_lines_luma * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k]), v->effective_detlb_lines_chroma * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0) - v->effective_detlb_lines_chroma * v->swath_width_yper_state[i][j][k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / (v->return_bw_per_state[i] / v->no_of_dpp[i][j][k])); 568 } 569 } 570 } 571 } 572 for (i = 0; i <= number_of_states_plus_one; i++) { 573 for (j = 0; j <= 1; j++) { 574 v->urgent_latency_support[i][j] = dcn_bw_yes; 575 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 576 if (v->urgent_latency_support_us_per_state[i][j][k] < v->urgent_latency / 1.0) { 577 v->urgent_latency_support[i][j] = dcn_bw_no; 578 } 579 } 580 } 581 } 582 /*prefetch check*/ 583 584 for (i = 0; i <= number_of_states_plus_one; i++) { 585 for (j = 0; j <= 1; j++) { 586 v->total_number_of_dcc_active_dpp[i][j] = 0.0; 587 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 588 if (v->dcc_enable[k] == dcn_bw_yes) { 589 v->total_number_of_dcc_active_dpp[i][j] = v->total_number_of_dcc_active_dpp[i][j] + v->no_of_dpp[i][j][k]; 590 } 591 } 592 } 593 } 594 for (i = 0; i <= number_of_states_plus_one; i++) { 595 for (j = 0; j <= 1; j++) { 596 v->projected_dcfclk_deep_sleep = 8.0; 597 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 598 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, v->pixel_clock[k] / 16.0); 599 if (v->byte_per_pixel_in_detc[k] == 0.0) { 600 if (v->v_ratio[k] <= 1.0) { 601 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 64.0 * v->h_ratio[k] * v->pixel_clock[k] / v->no_of_dpp[i][j][k]); 602 } 603 else { 604 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 64.0 * v->pscl_factor[k] * v->required_dispclk[i][j] / (1 + j)); 605 } 606 } 607 else { 608 if (v->v_ratio[k] <= 1.0) { 609 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 32.0 * v->h_ratio[k] * v->pixel_clock[k] / v->no_of_dpp[i][j][k]); 610 } 611 else { 612 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 32.0 * v->pscl_factor[k] * v->required_dispclk[i][j] / (1 + j)); 613 } 614 if (v->v_ratio[k] / 2.0 <= 1.0) { 615 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 32.0 * v->h_ratio[k] / 2.0 * v->pixel_clock[k] / v->no_of_dpp[i][j][k]); 616 } 617 else { 618 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, 1.1 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 32.0 * v->pscl_factor_chroma[k] * v->required_dispclk[i][j] / (1 + j)); 619 } 620 } 621 } 622 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 623 if (v->dcc_enable[k] == dcn_bw_yes) { 624 v->meta_req_height_y = 8.0 * v->read256_block_height_y[k]; 625 v->meta_req_width_y = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->meta_req_height_y; 626 v->meta_surface_width_y =dcn_bw_ceil2(v->viewport_width[k] / v->no_of_dpp[i][j][k] - 1.0, v->meta_req_width_y) + v->meta_req_width_y; 627 v->meta_surface_height_y =dcn_bw_ceil2(v->viewport_height[k] - 1.0, v->meta_req_height_y) + v->meta_req_height_y; 628 if (v->pte_enable == dcn_bw_yes) { 629 v->meta_pte_bytes_per_frame_y = (dcn_bw_ceil2((v->meta_surface_width_y * v->meta_surface_height_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0; 630 } 631 else { 632 v->meta_pte_bytes_per_frame_y = 0.0; 633 } 634 if (v->source_scan[k] == dcn_bw_hor) { 635 v->meta_row_bytes_y = v->meta_surface_width_y * v->meta_req_height_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0; 636 } 637 else { 638 v->meta_row_bytes_y = v->meta_surface_height_y * v->meta_req_width_y *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / 256.0; 639 } 640 } 641 else { 642 v->meta_pte_bytes_per_frame_y = 0.0; 643 v->meta_row_bytes_y = 0.0; 644 } 645 if (v->pte_enable == dcn_bw_yes) { 646 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 647 v->macro_tile_block_size_bytes_y = 256.0; 648 v->macro_tile_block_height_y = 1.0; 649 } 650 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) { 651 v->macro_tile_block_size_bytes_y = 4096.0; 652 v->macro_tile_block_height_y = 4.0 * v->read256_block_height_y[k]; 653 } 654 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) { 655 v->macro_tile_block_size_bytes_y = 64.0 * 1024; 656 v->macro_tile_block_height_y = 16.0 * v->read256_block_height_y[k]; 657 } 658 else { 659 v->macro_tile_block_size_bytes_y = 256.0 * 1024; 660 v->macro_tile_block_height_y = 32.0 * v->read256_block_height_y[k]; 661 } 662 if (v->macro_tile_block_size_bytes_y <= 65536.0) { 663 v->data_pte_req_height_y = v->macro_tile_block_height_y; 664 } 665 else { 666 v->data_pte_req_height_y = 16.0 * v->read256_block_height_y[k]; 667 } 668 v->data_pte_req_width_y = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) / v->data_pte_req_height_y * 8; 669 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 670 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] *dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->data_pte_req_width_y / (v->viewport_width[k] / v->no_of_dpp[i][j][k]), 2.0), 1.0))) - 1.0) / v->data_pte_req_width_y, 1.0) + 1); 671 } 672 else if (v->source_scan[k] == dcn_bw_hor) { 673 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] - 1.0) / v->data_pte_req_width_y, 1.0) + 1); 674 } 675 else { 676 v->dpte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] - 1.0) / v->data_pte_req_height_y, 1.0) + 1); 677 } 678 } 679 else { 680 v->dpte_bytes_per_row_y = 0.0; 681 } 682 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) { 683 if (v->dcc_enable[k] == dcn_bw_yes) { 684 v->meta_req_height_c = 8.0 * v->read256_block_height_c[k]; 685 v->meta_req_width_c = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->meta_req_height_c; 686 v->meta_surface_width_c =dcn_bw_ceil2(v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 - 1.0, v->meta_req_width_c) + v->meta_req_width_c; 687 v->meta_surface_height_c =dcn_bw_ceil2(v->viewport_height[k] / 2.0 - 1.0, v->meta_req_height_c) + v->meta_req_height_c; 688 if (v->pte_enable == dcn_bw_yes) { 689 v->meta_pte_bytes_per_frame_c = (dcn_bw_ceil2((v->meta_surface_width_c * v->meta_surface_height_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0; 690 } 691 else { 692 v->meta_pte_bytes_per_frame_c = 0.0; 693 } 694 if (v->source_scan[k] == dcn_bw_hor) { 695 v->meta_row_bytes_c = v->meta_surface_width_c * v->meta_req_height_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0; 696 } 697 else { 698 v->meta_row_bytes_c = v->meta_surface_height_c * v->meta_req_width_c *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 256.0; 699 } 700 } 701 else { 702 v->meta_pte_bytes_per_frame_c = 0.0; 703 v->meta_row_bytes_c = 0.0; 704 } 705 if (v->pte_enable == dcn_bw_yes) { 706 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 707 v->macro_tile_block_size_bytes_c = 256.0; 708 v->macro_tile_block_height_c = 1.0; 709 } 710 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) { 711 v->macro_tile_block_size_bytes_c = 4096.0; 712 v->macro_tile_block_height_c = 4.0 * v->read256_block_height_c[k]; 713 } 714 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) { 715 v->macro_tile_block_size_bytes_c = 64.0 * 1024; 716 v->macro_tile_block_height_c = 16.0 * v->read256_block_height_c[k]; 717 } 718 else { 719 v->macro_tile_block_size_bytes_c = 256.0 * 1024; 720 v->macro_tile_block_height_c = 32.0 * v->read256_block_height_c[k]; 721 } 722 v->macro_tile_block_width_c = v->macro_tile_block_size_bytes_c /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->macro_tile_block_height_c; 723 if (v->macro_tile_block_size_bytes_c <= 65536.0) { 724 v->data_pte_req_height_c = v->macro_tile_block_height_c; 725 } 726 else { 727 v->data_pte_req_height_c = 16.0 * v->read256_block_height_c[k]; 728 } 729 v->data_pte_req_width_c = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / v->data_pte_req_height_c * 8; 730 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 731 v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 * dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->data_pte_req_width_c / (v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0), 2.0), 1.0))) - 1.0) / v->data_pte_req_width_c, 1.0) + 1); 732 } 733 else if (v->source_scan[k] == dcn_bw_hor) { 734 v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_width[k] / v->no_of_dpp[i][j][k] / 2.0 - 1.0) / v->data_pte_req_width_c, 1.0) + 1); 735 } 736 else { 737 v->dpte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] / 2.0 - 1.0) / v->data_pte_req_height_c, 1.0) + 1); 738 } 739 } 740 else { 741 v->dpte_bytes_per_row_c = 0.0; 742 } 743 } 744 else { 745 v->dpte_bytes_per_row_c = 0.0; 746 v->meta_pte_bytes_per_frame_c = 0.0; 747 v->meta_row_bytes_c = 0.0; 748 } 749 v->dpte_bytes_per_row[k] = v->dpte_bytes_per_row_y + v->dpte_bytes_per_row_c; 750 v->meta_pte_bytes_per_frame[k] = v->meta_pte_bytes_per_frame_y + v->meta_pte_bytes_per_frame_c; 751 v->meta_row_bytes[k] = v->meta_row_bytes_y + v->meta_row_bytes_c; 752 v->v_init_y = (v->v_ratio[k] + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k]) / 2.0; 753 v->prefill_y[k] =dcn_bw_floor2(v->v_init_y, 1.0); 754 v->max_num_sw_y[k] =dcn_bw_ceil2((v->prefill_y[k] - 1.0) / v->swath_height_yper_state[i][j][k], 1.0) + 1; 755 if (v->prefill_y[k] > 1.0) { 756 v->max_partial_sw_y =dcn_bw_mod((v->prefill_y[k] - 2.0), v->swath_height_yper_state[i][j][k]); 757 } 758 else { 759 v->max_partial_sw_y =dcn_bw_mod((v->prefill_y[k] + v->swath_height_yper_state[i][j][k] - 2.0), v->swath_height_yper_state[i][j][k]); 760 } 761 v->max_partial_sw_y =dcn_bw_max2(1.0, v->max_partial_sw_y); 762 v->prefetch_lines_y[k] = v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k] + v->max_partial_sw_y; 763 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) { 764 v->v_init_c = (v->v_ratio[k] / 2.0 + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k] / 2.0) / 2.0; 765 v->prefill_c[k] =dcn_bw_floor2(v->v_init_c, 1.0); 766 v->max_num_sw_c[k] =dcn_bw_ceil2((v->prefill_c[k] - 1.0) / v->swath_height_cper_state[i][j][k], 1.0) + 1; 767 if (v->prefill_c[k] > 1.0) { 768 v->max_partial_sw_c =dcn_bw_mod((v->prefill_c[k] - 2.0), v->swath_height_cper_state[i][j][k]); 769 } 770 else { 771 v->max_partial_sw_c =dcn_bw_mod((v->prefill_c[k] + v->swath_height_cper_state[i][j][k] - 2.0), v->swath_height_cper_state[i][j][k]); 772 } 773 v->max_partial_sw_c =dcn_bw_max2(1.0, v->max_partial_sw_c); 774 v->prefetch_lines_c[k] = v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k] + v->max_partial_sw_c; 775 } 776 else { 777 v->prefetch_lines_c[k] = 0.0; 778 } 779 v->dst_x_after_scaler = 90.0 * v->pixel_clock[k] / (v->required_dispclk[i][j] / (j + 1)) + 42.0 * v->pixel_clock[k] / v->required_dispclk[i][j]; 780 if (v->no_of_dpp[i][j][k] > 1.0) { 781 v->dst_x_after_scaler = v->dst_x_after_scaler + v->scaler_rec_out_width[k] / 2.0; 782 } 783 if (v->output_format[k] == dcn_bw_420) { 784 v->dst_y_after_scaler = 1.0; 785 } 786 else { 787 v->dst_y_after_scaler = 0.0; 788 } 789 v->time_calc = 24.0 / v->projected_dcfclk_deep_sleep; 790 v->v_update_offset[k][j] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0); 791 v->total_repeater_delay = v->max_inter_dcn_tile_repeaters * (2.0 / (v->required_dispclk[i][j] / (j + 1)) + 3.0 / v->required_dispclk[i][j]); 792 v->v_update_width[k][j] = (14.0 / v->projected_dcfclk_deep_sleep + 12.0 / (v->required_dispclk[i][j] / (j + 1)) + v->total_repeater_delay) * v->pixel_clock[k]; 793 v->v_ready_offset[k][j] = dcn_bw_max2(150.0 / (v->required_dispclk[i][j] / (j + 1)), v->total_repeater_delay + 20.0 / v->projected_dcfclk_deep_sleep + 10.0 / (v->required_dispclk[i][j] / (j + 1))) * v->pixel_clock[k]; 794 v->time_setup = (v->v_update_offset[k][j] + v->v_update_width[k][j] + v->v_ready_offset[k][j]) / v->pixel_clock[k]; 795 v->extra_latency = v->urgent_round_trip_and_out_of_order_latency_per_state[i] + (v->total_number_of_active_dpp[i][j] * v->pixel_chunk_size_in_kbyte + v->total_number_of_dcc_active_dpp[i][j] * v->meta_chunk_size) * 1024.0 / v->return_bw_per_state[i]; 796 if (v->pte_enable == dcn_bw_yes) { 797 v->extra_latency = v->extra_latency + v->total_number_of_active_dpp[i][j] * v->pte_chunk_size * 1024.0 / v->return_bw_per_state[i]; 798 } 799 if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) { 800 v->maximum_vstartup = v->vtotal[k] - v->vactive[k] - 1.0; 801 } 802 else { 803 v->maximum_vstartup = v->v_sync_plus_back_porch[k] - 1.0; 804 } 805 806 do { 807 v->line_times_for_prefetch[k] = v->maximum_vstartup - v->urgent_latency / (v->htotal[k] / v->pixel_clock[k]) - (v->time_calc + v->time_setup) / (v->htotal[k] / v->pixel_clock[k]) - (v->dst_y_after_scaler + v->dst_x_after_scaler / v->htotal[k]); 808 v->line_times_for_prefetch[k] =dcn_bw_floor2(4.0 * (v->line_times_for_prefetch[k] + 0.125), 1.0) / 4; 809 v->prefetch_bw[k] = (v->meta_pte_bytes_per_frame[k] + 2.0 * v->meta_row_bytes[k] + 2.0 * v->dpte_bytes_per_row[k] + v->prefetch_lines_y[k] * v->swath_width_yper_state[i][j][k] *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] * v->swath_width_yper_state[i][j][k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0)) / (v->line_times_for_prefetch[k] * v->htotal[k] / v->pixel_clock[k]); 810 811 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) { 812 v->time_for_meta_pte_without_immediate_flip = dcn_bw_max3( 813 v->meta_pte_bytes_frame[k] / v->prefetch_bandwidth[k], 814 v->extra_latency, 815 v->htotal[k] / v->pixel_clock[k] / 4.0); 816 } else { 817 v->time_for_meta_pte_without_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0; 818 } 819 820 if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) { 821 v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max3(( 822 v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / v->prefetch_bandwidth[k], 823 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip, 824 v->extra_latency); 825 } else { 826 v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max2( 827 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip, 828 v->extra_latency - v->time_for_meta_pte_with_immediate_flip); 829 } 830 831 v->lines_for_meta_pte_without_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_pte_without_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 832 v->lines_for_meta_and_dpte_row_without_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_and_dpte_row_without_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 833 v->maximum_vstartup = v->maximum_vstartup - 1; 834 835 if (v->lines_for_meta_pte_without_immediate_flip[k] < 8.0 && v->lines_for_meta_and_dpte_row_without_immediate_flip[k] < 16.0) 836 break; 837 838 } while(1); 839 } 840 v->bw_available_for_immediate_flip = v->return_bw_per_state[i]; 841 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 842 v->bw_available_for_immediate_flip = v->bw_available_for_immediate_flip -dcn_bw_max2(v->read_bandwidth[k], v->prefetch_bw[k]); 843 } 844 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 845 v->total_immediate_flip_bytes[k] = 0.0; 846 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 847 v->total_immediate_flip_bytes[k] = v->total_immediate_flip_bytes[k] + v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]; 848 } 849 } 850 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 851 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) { 852 v->time_for_meta_pte_with_immediate_flip =dcn_bw_max5(v->meta_pte_bytes_per_frame[k] / v->prefetch_bw[k], v->meta_pte_bytes_per_frame[k] * v->total_immediate_flip_bytes[k] / (v->bw_available_for_immediate_flip * (v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k])), v->extra_latency, v->urgent_latency, v->htotal[k] / v->pixel_clock[k] / 4.0); 853 } 854 else { 855 v->time_for_meta_pte_with_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0; 856 } 857 if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) { 858 v->time_for_meta_and_dpte_row_with_immediate_flip =dcn_bw_max5((v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / v->prefetch_bw[k], (v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) * v->total_immediate_flip_bytes[k] / (v->bw_available_for_immediate_flip * (v->meta_pte_bytes_per_frame[k] + v->meta_row_bytes[k] + v->dpte_bytes_per_row[k])), v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_with_immediate_flip, v->extra_latency, 2.0 * v->urgent_latency); 859 } 860 else { 861 v->time_for_meta_and_dpte_row_with_immediate_flip =dcn_bw_max2(v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_with_immediate_flip, v->extra_latency - v->time_for_meta_pte_with_immediate_flip); 862 } 863 v->lines_for_meta_pte_with_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_pte_with_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 864 v->lines_for_meta_and_dpte_row_with_immediate_flip[k] =dcn_bw_floor2(4.0 * (v->time_for_meta_and_dpte_row_with_immediate_flip / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 865 v->line_times_to_request_prefetch_pixel_data_with_immediate_flip = v->line_times_for_prefetch[k] - v->lines_for_meta_pte_with_immediate_flip[k] - v->lines_for_meta_and_dpte_row_with_immediate_flip[k]; 866 v->line_times_to_request_prefetch_pixel_data_without_immediate_flip = v->line_times_for_prefetch[k] - v->lines_for_meta_pte_without_immediate_flip[k] - v->lines_for_meta_and_dpte_row_without_immediate_flip[k]; 867 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip > 0.0) { 868 v->v_ratio_pre_ywith_immediate_flip[i][j][k] = v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip; 869 if ((v->swath_height_yper_state[i][j][k] > 4.0)) { 870 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) { 871 v->v_ratio_pre_ywith_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_ywith_immediate_flip[i][j][k], (v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0)); 872 } 873 else { 874 v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0; 875 } 876 } 877 v->v_ratio_pre_cwith_immediate_flip[i][j][k] = v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip; 878 if ((v->swath_height_cper_state[i][j][k] > 4.0)) { 879 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) { 880 v->v_ratio_pre_cwith_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_cwith_immediate_flip[i][j][k], (v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0)); 881 } 882 else { 883 v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0; 884 } 885 } 886 v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k] = v->no_of_dpp[i][j][k] * (v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_with_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0) * v->swath_width_yper_state[i][j][k] / (v->htotal[k] / v->pixel_clock[k]); 887 } 888 else { 889 v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0; 890 v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0; 891 v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k] = 999999.0; 892 } 893 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip > 0.0) { 894 v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip; 895 if ((v->swath_height_yper_state[i][j][k] > 4.0)) { 896 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) { 897 v->v_ratio_pre_ywithout_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_ywithout_immediate_flip[i][j][k], (v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0)); 898 } 899 else { 900 v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0; 901 } 902 } 903 v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip; 904 if ((v->swath_height_cper_state[i][j][k] > 4.0)) { 905 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) { 906 v->v_ratio_pre_cwithout_immediate_flip[i][j][k] =dcn_bw_max2(v->v_ratio_pre_cwithout_immediate_flip[i][j][k], (v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k]) / (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0)); 907 } 908 else { 909 v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0; 910 } 911 } 912 v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k] = v->no_of_dpp[i][j][k] * (v->prefetch_lines_y[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_dety[k], 1.0) + v->prefetch_lines_c[k] / v->line_times_to_request_prefetch_pixel_data_without_immediate_flip *dcn_bw_ceil2(v->byte_per_pixel_in_detc[k], 2.0) / 2.0) * v->swath_width_yper_state[i][j][k] / (v->htotal[k] / v->pixel_clock[k]); 913 } 914 else { 915 v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0; 916 v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0; 917 v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k] = 999999.0; 918 } 919 } 920 v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = 0.0; 921 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 922 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 923 v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = v->maximum_read_bandwidth_with_prefetch_with_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k]) +dcn_bw_max2(v->meta_pte_bytes_per_frame[k] / (v->lines_for_meta_pte_with_immediate_flip[k] * v->htotal[k] / v->pixel_clock[k]), (v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / (v->lines_for_meta_and_dpte_row_with_immediate_flip[k] * v->htotal[k] / v->pixel_clock[k])); 924 } 925 else { 926 v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = v->maximum_read_bandwidth_with_prefetch_with_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k]); 927 } 928 } 929 v->maximum_read_bandwidth_with_prefetch_without_immediate_flip = 0.0; 930 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 931 v->maximum_read_bandwidth_with_prefetch_without_immediate_flip = v->maximum_read_bandwidth_with_prefetch_without_immediate_flip +dcn_bw_max2(v->read_bandwidth[k], v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k]); 932 } 933 v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes; 934 if (v->maximum_read_bandwidth_with_prefetch_with_immediate_flip > v->return_bw_per_state[i]) { 935 v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no; 936 } 937 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 938 if (v->line_times_for_prefetch[k] < 2.0 || v->lines_for_meta_pte_with_immediate_flip[k] >= 8.0 || v->lines_for_meta_and_dpte_row_with_immediate_flip[k] >= 16.0) { 939 v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no; 940 } 941 } 942 v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes; 943 if (v->maximum_read_bandwidth_with_prefetch_without_immediate_flip > v->return_bw_per_state[i]) { 944 v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no; 945 } 946 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 947 if (v->line_times_for_prefetch[k] < 2.0 || v->lines_for_meta_pte_without_immediate_flip[k] >= 8.0 || v->lines_for_meta_and_dpte_row_without_immediate_flip[k] >= 16.0) { 948 v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no; 949 } 950 } 951 } 952 } 953 for (i = 0; i <= number_of_states_plus_one; i++) { 954 for (j = 0; j <= 1; j++) { 955 v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes; 956 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 957 if ((((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10) && (v->v_ratio_pre_ywith_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwith_immediate_flip[i][j][k] > 4.0)) || ((v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 || v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) && (v->v_ratio_pre_ywithout_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwithout_immediate_flip[i][j][k] > 4.0)))) { 958 v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no; 959 } 960 } 961 v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes; 962 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 963 if ((v->v_ratio_pre_ywithout_immediate_flip[i][j][k] > 4.0 || v->v_ratio_pre_cwithout_immediate_flip[i][j][k] > 4.0)) { 964 v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no; 965 } 966 } 967 } 968 } 969 /*mode support, voltage state and soc configuration*/ 970 971 for (i = number_of_states_plus_one; i >= 0; i--) { 972 for (j = 0; j <= 1; j++) { 973 if (v->scale_ratio_support == dcn_bw_yes && v->source_format_pixel_and_scan_support == dcn_bw_yes && v->viewport_size_support == dcn_bw_yes && v->bandwidth_support[i] == dcn_bw_yes && v->dio_support[i] == dcn_bw_yes && v->urgent_latency_support[i][j] == dcn_bw_yes && v->rob_support[i] == dcn_bw_yes && v->dispclk_dppclk_support[i][j] == dcn_bw_yes && v->total_available_pipes_support[i][j] == dcn_bw_yes && v->total_available_writeback_support == dcn_bw_yes && v->writeback_latency_support == dcn_bw_yes) { 974 if (v->prefetch_supported_with_immediate_flip[i][j] == dcn_bw_yes && v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] == dcn_bw_yes) { 975 v->mode_support_with_immediate_flip[i][j] = dcn_bw_yes; 976 } 977 else { 978 v->mode_support_with_immediate_flip[i][j] = dcn_bw_no; 979 } 980 if (v->prefetch_supported_without_immediate_flip[i][j] == dcn_bw_yes && v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] == dcn_bw_yes) { 981 v->mode_support_without_immediate_flip[i][j] = dcn_bw_yes; 982 } 983 else { 984 v->mode_support_without_immediate_flip[i][j] = dcn_bw_no; 985 } 986 } 987 else { 988 v->mode_support_with_immediate_flip[i][j] = dcn_bw_no; 989 v->mode_support_without_immediate_flip[i][j] = dcn_bw_no; 990 } 991 } 992 } 993 for (i = number_of_states_plus_one; i >= 0; i--) { 994 if ((i == number_of_states_plus_one || v->mode_support_with_immediate_flip[i][1] == dcn_bw_yes || v->mode_support_with_immediate_flip[i][0] == dcn_bw_yes) && i >= v->voltage_override_level) { 995 v->voltage_level_with_immediate_flip = i; 996 } 997 } 998 for (i = number_of_states_plus_one; i >= 0; i--) { 999 if ((i == number_of_states_plus_one || v->mode_support_without_immediate_flip[i][1] == dcn_bw_yes || v->mode_support_without_immediate_flip[i][0] == dcn_bw_yes) && i >= v->voltage_override_level) { 1000 v->voltage_level_without_immediate_flip = i; 1001 } 1002 } 1003 if (v->voltage_level_with_immediate_flip == number_of_states_plus_one) { 1004 v->immediate_flip_supported = dcn_bw_no; 1005 v->voltage_level = v->voltage_level_without_immediate_flip; 1006 } 1007 else { 1008 v->immediate_flip_supported = dcn_bw_yes; 1009 v->voltage_level = v->voltage_level_with_immediate_flip; 1010 } 1011 v->dcfclk = v->dcfclk_per_state[v->voltage_level]; 1012 v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_per_state[v->voltage_level]; 1013 for (j = 0; j <= 1; j++) { 1014 v->required_dispclk_per_ratio[j] = v->required_dispclk[v->voltage_level][j]; 1015 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1016 v->dpp_per_plane_per_ratio[j][k] = v->no_of_dpp[v->voltage_level][j][k]; 1017 } 1018 v->dispclk_dppclk_support_per_ratio[j] = v->dispclk_dppclk_support[v->voltage_level][j]; 1019 } 1020 v->max_phyclk = v->phyclk_per_state[v->voltage_level]; 1021 } 1022 void display_pipe_configuration(struct dcn_bw_internal_vars *v) 1023 { 1024 int j; 1025 int k; 1026 /*display pipe configuration*/ 1027 1028 for (j = 0; j <= 1; j++) { 1029 v->total_number_of_active_dpp_per_ratio[j] = 0.0; 1030 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1031 v->total_number_of_active_dpp_per_ratio[j] = v->total_number_of_active_dpp_per_ratio[j] + v->dpp_per_plane_per_ratio[j][k]; 1032 } 1033 } 1034 if ((v->dispclk_dppclk_support_per_ratio[0] == dcn_bw_yes && v->dispclk_dppclk_support_per_ratio[1] == dcn_bw_no) || (v->dispclk_dppclk_support_per_ratio[0] == v->dispclk_dppclk_support_per_ratio[1] && (v->total_number_of_active_dpp_per_ratio[0] < v->total_number_of_active_dpp_per_ratio[1] || (((v->total_number_of_active_dpp_per_ratio[0] == v->total_number_of_active_dpp_per_ratio[1]) && v->required_dispclk_per_ratio[0] <= 0.5 * v->required_dispclk_per_ratio[1]))))) { 1035 v->dispclk_dppclk_ratio = 1; 1036 v->final_error_message = v->error_message[0]; 1037 } 1038 else { 1039 v->dispclk_dppclk_ratio = 2; 1040 v->final_error_message = v->error_message[1]; 1041 } 1042 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1043 v->dpp_per_plane[k] = v->dpp_per_plane_per_ratio[v->dispclk_dppclk_ratio - 1][k]; 1044 } 1045 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1046 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 1047 v->byte_per_pix_dety = 8.0; 1048 v->byte_per_pix_detc = 0.0; 1049 } 1050 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) { 1051 v->byte_per_pix_dety = 4.0; 1052 v->byte_per_pix_detc = 0.0; 1053 } 1054 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) { 1055 v->byte_per_pix_dety = 2.0; 1056 v->byte_per_pix_detc = 0.0; 1057 } 1058 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 1059 v->byte_per_pix_dety = 1.0; 1060 v->byte_per_pix_detc = 2.0; 1061 } 1062 else { 1063 v->byte_per_pix_dety = 4.0f / 3.0f; 1064 v->byte_per_pix_detc = 8.0f / 3.0f; 1065 } 1066 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) { 1067 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1068 v->read256_bytes_block_height_y = 1.0; 1069 } 1070 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 1071 v->read256_bytes_block_height_y = 4.0; 1072 } 1073 else { 1074 v->read256_bytes_block_height_y = 8.0; 1075 } 1076 v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y; 1077 v->read256_bytes_block_height_c = 0.0; 1078 v->read256_bytes_block_width_c = 0.0; 1079 } 1080 else { 1081 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1082 v->read256_bytes_block_height_y = 1.0; 1083 v->read256_bytes_block_height_c = 1.0; 1084 } 1085 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 1086 v->read256_bytes_block_height_y = 16.0; 1087 v->read256_bytes_block_height_c = 8.0; 1088 } 1089 else { 1090 v->read256_bytes_block_height_y = 8.0; 1091 v->read256_bytes_block_height_c = 8.0; 1092 } 1093 v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y; 1094 v->read256_bytes_block_width_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->read256_bytes_block_height_c; 1095 } 1096 if (v->source_scan[k] == dcn_bw_hor) { 1097 v->maximum_swath_height_y = v->read256_bytes_block_height_y; 1098 v->maximum_swath_height_c = v->read256_bytes_block_height_c; 1099 } 1100 else { 1101 v->maximum_swath_height_y = v->read256_bytes_block_width_y; 1102 v->maximum_swath_height_c = v->read256_bytes_block_width_c; 1103 } 1104 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) { 1105 if (v->source_surface_mode[k] == dcn_bw_sw_linear || (v->source_pixel_format[k] == dcn_bw_rgb_sub_64 && (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_var_s || v->source_surface_mode[k] == dcn_bw_sw_var_s_x) && v->source_scan[k] == dcn_bw_hor)) { 1106 v->minimum_swath_height_y = v->maximum_swath_height_y; 1107 } 1108 else { 1109 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0; 1110 } 1111 v->minimum_swath_height_c = v->maximum_swath_height_c; 1112 } 1113 else { 1114 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1115 v->minimum_swath_height_y = v->maximum_swath_height_y; 1116 v->minimum_swath_height_c = v->maximum_swath_height_c; 1117 } 1118 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) { 1119 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0; 1120 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) { 1121 v->minimum_swath_height_c = v->maximum_swath_height_c; 1122 } 1123 else { 1124 v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0; 1125 } 1126 } 1127 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) { 1128 v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0; 1129 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) { 1130 v->minimum_swath_height_y = v->maximum_swath_height_y; 1131 } 1132 else { 1133 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0; 1134 } 1135 } 1136 else { 1137 v->minimum_swath_height_y = v->maximum_swath_height_y; 1138 v->minimum_swath_height_c = v->maximum_swath_height_c; 1139 } 1140 } 1141 if (v->source_scan[k] == dcn_bw_hor) { 1142 v->swath_width = v->viewport_width[k] / v->dpp_per_plane[k]; 1143 } 1144 else { 1145 v->swath_width = v->viewport_height[k] / v->dpp_per_plane[k]; 1146 } 1147 v->swath_width_granularity_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->maximum_swath_height_y; 1148 v->rounded_up_max_swath_size_bytes_y = (dcn_bw_ceil2(v->swath_width - 1.0, v->swath_width_granularity_y) + v->swath_width_granularity_y) * v->byte_per_pix_dety * v->maximum_swath_height_y; 1149 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) { 1150 v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256; 1151 } 1152 if (v->maximum_swath_height_c > 0.0) { 1153 v->swath_width_granularity_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->maximum_swath_height_c; 1154 } 1155 v->rounded_up_max_swath_size_bytes_c = (dcn_bw_ceil2(v->swath_width / 2.0 - 1.0, v->swath_width_granularity_c) + v->swath_width_granularity_c) * v->byte_per_pix_detc * v->maximum_swath_height_c; 1156 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) { 1157 v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256; 1158 } 1159 if (v->rounded_up_max_swath_size_bytes_y + v->rounded_up_max_swath_size_bytes_c <= v->det_buffer_size_in_kbyte * 1024.0 / 2.0) { 1160 v->swath_height_y[k] = v->maximum_swath_height_y; 1161 v->swath_height_c[k] = v->maximum_swath_height_c; 1162 } 1163 else { 1164 v->swath_height_y[k] = v->minimum_swath_height_y; 1165 v->swath_height_c[k] = v->minimum_swath_height_c; 1166 } 1167 if (v->swath_height_c[k] == 0.0) { 1168 v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0; 1169 v->det_buffer_size_c[k] = 0.0; 1170 } 1171 else if (v->swath_height_y[k] <= v->swath_height_c[k]) { 1172 v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0; 1173 v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0; 1174 } 1175 else { 1176 v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 * 2.0 / 3.0; 1177 v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 3.0; 1178 } 1179 } 1180 } 1181 void dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(struct dcn_bw_internal_vars *v) 1182 { 1183 int k; 1184 /*dispclk and dppclk calculation*/ 1185 1186 v->dispclk_with_ramping = 0.0; 1187 v->dispclk_without_ramping = 0.0; 1188 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1189 if (v->h_ratio[k] > 1.0) { 1190 v->pscl_throughput[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] /dcn_bw_ceil2(v->htaps[k] / 6.0, 1.0)); 1191 } 1192 else { 1193 v->pscl_throughput[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput); 1194 } 1195 v->dppclk_using_single_dpp_luma = v->pixel_clock[k] *dcn_bw_max3(v->vtaps[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k]), v->h_ratio[k] * v->v_ratio[k] / v->pscl_throughput[k], 1.0); 1196 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 1197 v->pscl_throughput_chroma[k] = 0.0; 1198 v->dppclk_using_single_dpp = v->dppclk_using_single_dpp_luma; 1199 } 1200 else { 1201 if (v->h_ratio[k] > 1.0) { 1202 v->pscl_throughput_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput * v->h_ratio[k] / 2.0 /dcn_bw_ceil2(v->hta_pschroma[k] / 6.0, 1.0)); 1203 } 1204 else { 1205 v->pscl_throughput_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput); 1206 } 1207 v->dppclk_using_single_dpp_chroma = v->pixel_clock[k] *dcn_bw_max3(v->vta_pschroma[k] / 6.0 *dcn_bw_min2(1.0, v->h_ratio[k] / 2.0), v->h_ratio[k] * v->v_ratio[k] / 4.0 / v->pscl_throughput_chroma[k], 1.0); 1208 v->dppclk_using_single_dpp =dcn_bw_max2(v->dppclk_using_single_dpp_luma, v->dppclk_using_single_dpp_chroma); 1209 } 1210 if (v->odm_capable == dcn_bw_yes) { 1211 v->dispclk_with_ramping =dcn_bw_max2(v->dispclk_with_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k] / v->dpp_per_plane[k]) * (1.0 + v->downspreading / 100.0) * (1.0 + v->dispclk_ramping_margin / 100.0)); 1212 v->dispclk_without_ramping =dcn_bw_max2(v->dispclk_without_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k] / v->dpp_per_plane[k]) * (1.0 + v->downspreading / 100.0)); 1213 } 1214 else { 1215 v->dispclk_with_ramping =dcn_bw_max2(v->dispclk_with_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k]) * (1.0 + v->downspreading / 100.0) * (1.0 + v->dispclk_ramping_margin / 100.0)); 1216 v->dispclk_without_ramping =dcn_bw_max2(v->dispclk_without_ramping,dcn_bw_max2(v->dppclk_using_single_dpp / v->dpp_per_plane[k] * v->dispclk_dppclk_ratio, v->pixel_clock[k]) * (1.0 + v->downspreading / 100.0)); 1217 } 1218 } 1219 if (v->dispclk_without_ramping > v->max_dispclk[number_of_states]) { 1220 v->dispclk = v->dispclk_without_ramping; 1221 } 1222 else if (v->dispclk_with_ramping > v->max_dispclk[number_of_states]) { 1223 v->dispclk = v->max_dispclk[number_of_states]; 1224 } 1225 else { 1226 v->dispclk = v->dispclk_with_ramping; 1227 } 1228 v->dppclk = v->dispclk / v->dispclk_dppclk_ratio; 1229 /*urgent watermark*/ 1230 1231 v->return_bandwidth_to_dcn =dcn_bw_min2(v->return_bus_width * v->dcfclk, v->fabric_and_dram_bandwidth * 1000.0 * v->percent_of_ideal_drambw_received_after_urg_latency / 100.0); 1232 v->dcc_enabled_any_plane = dcn_bw_no; 1233 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1234 if (v->dcc_enable[k] == dcn_bw_yes) { 1235 v->dcc_enabled_any_plane = dcn_bw_yes; 1236 } 1237 } 1238 v->return_bw = v->return_bandwidth_to_dcn; 1239 if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) { 1240 v->return_bw =dcn_bw_min2(v->return_bw, v->return_bandwidth_to_dcn * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bandwidth_to_dcn - v->dcfclk * v->return_bus_width / 4.0) + v->urgent_latency))); 1241 } 1242 v->critical_compression = 2.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0); 1243 if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) { 1244 v->return_bw =dcn_bw_min2(v->return_bw, dcn_bw_pow(4.0 * v->return_bandwidth_to_dcn * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2)); 1245 } 1246 v->return_bandwidth_to_dcn =dcn_bw_min2(v->return_bus_width * v->dcfclk, v->fabric_and_dram_bandwidth * 1000.0); 1247 if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) { 1248 v->return_bw =dcn_bw_min2(v->return_bw, v->return_bandwidth_to_dcn * 4.0 * (1.0 - v->urgent_latency / ((v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 / (v->return_bandwidth_to_dcn - v->dcfclk * v->return_bus_width / 4.0) + v->urgent_latency))); 1249 } 1250 v->critical_compression = 2.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0); 1251 if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) { 1252 v->return_bw =dcn_bw_min2(v->return_bw, dcn_bw_pow(4.0 * v->return_bandwidth_to_dcn * (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0 * v->return_bus_width * v->dcfclk * v->urgent_latency / (v->return_bandwidth_to_dcn * v->urgent_latency + (v->rob_buffer_size_in_kbyte - v->pixel_chunk_size_in_kbyte) * 1024.0), 2)); 1253 } 1254 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1255 if (v->source_scan[k] == dcn_bw_hor) { 1256 v->swath_width_y[k] = v->viewport_width[k] / v->dpp_per_plane[k]; 1257 } 1258 else { 1259 v->swath_width_y[k] = v->viewport_height[k] / v->dpp_per_plane[k]; 1260 } 1261 } 1262 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1263 if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 1264 v->byte_per_pixel_dety[k] = 8.0; 1265 v->byte_per_pixel_detc[k] = 0.0; 1266 } 1267 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) { 1268 v->byte_per_pixel_dety[k] = 4.0; 1269 v->byte_per_pixel_detc[k] = 0.0; 1270 } 1271 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) { 1272 v->byte_per_pixel_dety[k] = 2.0; 1273 v->byte_per_pixel_detc[k] = 0.0; 1274 } 1275 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 1276 v->byte_per_pixel_dety[k] = 1.0; 1277 v->byte_per_pixel_detc[k] = 2.0; 1278 } 1279 else { 1280 v->byte_per_pixel_dety[k] = 4.0f / 3.0f; 1281 v->byte_per_pixel_detc[k] = 8.0f / 3.0f; 1282 } 1283 } 1284 v->total_data_read_bandwidth = 0.0; 1285 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1286 v->read_bandwidth_plane_luma[k] = v->swath_width_y[k] * v->dpp_per_plane[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (v->htotal[k] / v->pixel_clock[k]) * v->v_ratio[k]; 1287 v->read_bandwidth_plane_chroma[k] = v->swath_width_y[k] / 2.0 * v->dpp_per_plane[k] *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (v->htotal[k] / v->pixel_clock[k]) * v->v_ratio[k] / 2.0; 1288 v->total_data_read_bandwidth = v->total_data_read_bandwidth + v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k]; 1289 } 1290 v->total_active_dpp = 0.0; 1291 v->total_dcc_active_dpp = 0.0; 1292 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1293 v->total_active_dpp = v->total_active_dpp + v->dpp_per_plane[k]; 1294 if (v->dcc_enable[k] == dcn_bw_yes) { 1295 v->total_dcc_active_dpp = v->total_dcc_active_dpp + v->dpp_per_plane[k]; 1296 } 1297 } 1298 v->urgent_round_trip_and_out_of_order_latency = (v->round_trip_ping_latency_cycles + 32.0) / v->dcfclk + v->urgent_out_of_order_return_per_channel * v->number_of_channels / v->return_bw; 1299 v->last_pixel_of_line_extra_watermark = 0.0; 1300 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1301 if (v->v_ratio[k] <= 1.0) { 1302 v->display_pipe_line_delivery_time_luma[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k]; 1303 } 1304 else { 1305 v->display_pipe_line_delivery_time_luma[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk; 1306 } 1307 v->data_fabric_line_delivery_time_luma = v->swath_width_y[k] * v->swath_height_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (v->return_bw * v->read_bandwidth_plane_luma[k] / v->dpp_per_plane[k] / v->total_data_read_bandwidth); 1308 v->last_pixel_of_line_extra_watermark =dcn_bw_max2(v->last_pixel_of_line_extra_watermark, v->data_fabric_line_delivery_time_luma - v->display_pipe_line_delivery_time_luma[k]); 1309 if (v->byte_per_pixel_detc[k] == 0.0) { 1310 v->display_pipe_line_delivery_time_chroma[k] = 0.0; 1311 } 1312 else { 1313 if (v->v_ratio[k] / 2.0 <= 1.0) { 1314 v->display_pipe_line_delivery_time_chroma[k] = v->swath_width_y[k] / 2.0 * v->dpp_per_plane[k] / (v->h_ratio[k] / 2.0) / v->pixel_clock[k]; 1315 } 1316 else { 1317 v->display_pipe_line_delivery_time_chroma[k] = v->swath_width_y[k] / 2.0 / v->pscl_throughput_chroma[k] / v->dppclk; 1318 } 1319 v->data_fabric_line_delivery_time_chroma = v->swath_width_y[k] / 2.0 * v->swath_height_c[k] *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (v->return_bw * v->read_bandwidth_plane_chroma[k] / v->dpp_per_plane[k] / v->total_data_read_bandwidth); 1320 v->last_pixel_of_line_extra_watermark =dcn_bw_max2(v->last_pixel_of_line_extra_watermark, v->data_fabric_line_delivery_time_chroma - v->display_pipe_line_delivery_time_chroma[k]); 1321 } 1322 } 1323 v->urgent_extra_latency = v->urgent_round_trip_and_out_of_order_latency + (v->total_active_dpp * v->pixel_chunk_size_in_kbyte + v->total_dcc_active_dpp * v->meta_chunk_size) * 1024.0 / v->return_bw; 1324 if (v->pte_enable == dcn_bw_yes) { 1325 v->urgent_extra_latency = v->urgent_extra_latency + v->total_active_dpp * v->pte_chunk_size * 1024.0 / v->return_bw; 1326 } 1327 v->urgent_watermark = v->urgent_latency + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency; 1328 v->ptemeta_urgent_watermark = v->urgent_watermark + 2.0 * v->urgent_latency; 1329 /*nb p-state/dram clock change watermark*/ 1330 1331 v->dram_clock_change_watermark = v->dram_clock_change_latency + v->urgent_watermark; 1332 v->total_active_writeback = 0.0; 1333 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1334 if (v->output[k] == dcn_bw_writeback) { 1335 v->total_active_writeback = v->total_active_writeback + 1.0; 1336 } 1337 } 1338 if (v->total_active_writeback <= 1.0) { 1339 v->writeback_dram_clock_change_watermark = v->dram_clock_change_latency + v->write_back_latency; 1340 } 1341 else { 1342 v->writeback_dram_clock_change_watermark = v->dram_clock_change_latency + v->write_back_latency + v->writeback_chunk_size * 1024.0 / 32.0 / v->socclk; 1343 } 1344 /*stutter efficiency*/ 1345 1346 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1347 v->lines_in_dety[k] = v->det_buffer_size_y[k] / v->byte_per_pixel_dety[k] / v->swath_width_y[k]; 1348 v->lines_in_dety_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_dety[k], v->swath_height_y[k]); 1349 v->full_det_buffering_time_y[k] = v->lines_in_dety_rounded_down_to_swath[k] * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k]; 1350 if (v->byte_per_pixel_detc[k] > 0.0) { 1351 v->lines_in_detc[k] = v->det_buffer_size_c[k] / v->byte_per_pixel_detc[k] / (v->swath_width_y[k] / 2.0); 1352 v->lines_in_detc_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_detc[k], v->swath_height_c[k]); 1353 v->full_det_buffering_time_c[k] = v->lines_in_detc_rounded_down_to_swath[k] * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0); 1354 } 1355 else { 1356 v->lines_in_detc[k] = 0.0; 1357 v->lines_in_detc_rounded_down_to_swath[k] = 0.0; 1358 v->full_det_buffering_time_c[k] = 999999.0; 1359 } 1360 } 1361 v->min_full_det_buffering_time = 999999.0; 1362 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1363 if (v->full_det_buffering_time_y[k] < v->min_full_det_buffering_time) { 1364 v->min_full_det_buffering_time = v->full_det_buffering_time_y[k]; 1365 v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k]; 1366 } 1367 if (v->full_det_buffering_time_c[k] < v->min_full_det_buffering_time) { 1368 v->min_full_det_buffering_time = v->full_det_buffering_time_c[k]; 1369 v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k]; 1370 } 1371 } 1372 v->average_read_bandwidth_gbyte_per_second = 0.0; 1373 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1374 if (v->dcc_enable[k] == dcn_bw_yes) { 1375 v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / v->dcc_rate[k] / 1000.0 + v->read_bandwidth_plane_chroma[k] / v->dcc_rate[k] / 1000.0; 1376 } 1377 else { 1378 v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 + v->read_bandwidth_plane_chroma[k] / 1000.0; 1379 } 1380 if (v->dcc_enable[k] == dcn_bw_yes) { 1381 v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 / 256.0 + v->read_bandwidth_plane_chroma[k] / 1000.0 / 256.0; 1382 } 1383 if (v->pte_enable == dcn_bw_yes) { 1384 v->average_read_bandwidth_gbyte_per_second = v->average_read_bandwidth_gbyte_per_second + v->read_bandwidth_plane_luma[k] / 1000.0 / 512.0 + v->read_bandwidth_plane_chroma[k] / 1000.0 / 512.0; 1385 } 1386 } 1387 v->part_of_burst_that_fits_in_rob =dcn_bw_min2(v->min_full_det_buffering_time * v->total_data_read_bandwidth, v->rob_buffer_size_in_kbyte * 1024.0 * v->total_data_read_bandwidth / (v->average_read_bandwidth_gbyte_per_second * 1000.0)); 1388 v->stutter_burst_time = v->part_of_burst_that_fits_in_rob * (v->average_read_bandwidth_gbyte_per_second * 1000.0) / v->total_data_read_bandwidth / v->return_bw + (v->min_full_det_buffering_time * v->total_data_read_bandwidth - v->part_of_burst_that_fits_in_rob) / (v->dcfclk * 64.0); 1389 if (v->total_active_writeback == 0.0) { 1390 v->stutter_efficiency_not_including_vblank = (1.0 - (v->sr_exit_time + v->stutter_burst_time) / v->min_full_det_buffering_time) * 100.0; 1391 } 1392 else { 1393 v->stutter_efficiency_not_including_vblank = 0.0; 1394 } 1395 v->smallest_vblank = 999999.0; 1396 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1397 if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) { 1398 v->v_blank_time = (v->vtotal[k] - v->vactive[k]) * v->htotal[k] / v->pixel_clock[k]; 1399 } 1400 else { 1401 v->v_blank_time = 0.0; 1402 } 1403 v->smallest_vblank =dcn_bw_min2(v->smallest_vblank, v->v_blank_time); 1404 } 1405 v->stutter_efficiency = (v->stutter_efficiency_not_including_vblank / 100.0 * (v->frame_time_for_min_full_det_buffering_time - v->smallest_vblank) + v->smallest_vblank) / v->frame_time_for_min_full_det_buffering_time * 100.0; 1406 /*dcfclk deep sleep*/ 1407 1408 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1409 if (v->byte_per_pixel_detc[k] > 0.0) { 1410 v->dcfclk_deep_sleep_per_plane[k] =dcn_bw_max2(1.1 * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 32.0 / v->display_pipe_line_delivery_time_luma[k], 1.1 * v->swath_width_y[k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 32.0 / v->display_pipe_line_delivery_time_chroma[k]); 1411 } 1412 else { 1413 v->dcfclk_deep_sleep_per_plane[k] = 1.1 * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 64.0 / v->display_pipe_line_delivery_time_luma[k]; 1414 } 1415 v->dcfclk_deep_sleep_per_plane[k] =dcn_bw_max2(v->dcfclk_deep_sleep_per_plane[k], v->pixel_clock[k] / 16.0); 1416 } 1417 v->dcf_clk_deep_sleep = 8.0; 1418 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1419 v->dcf_clk_deep_sleep =dcn_bw_max2(v->dcf_clk_deep_sleep, v->dcfclk_deep_sleep_per_plane[k]); 1420 } 1421 /*stutter watermark*/ 1422 1423 v->stutter_exit_watermark = v->sr_exit_time + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency + 10.0 / v->dcf_clk_deep_sleep; 1424 v->stutter_enter_plus_exit_watermark = v->sr_enter_plus_exit_time + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency; 1425 /*urgent latency supported*/ 1426 1427 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1428 v->effective_det_plus_lb_lines_luma =dcn_bw_floor2(v->lines_in_dety[k] +dcn_bw_min2(v->lines_in_dety[k] * v->dppclk * v->byte_per_pixel_dety[k] * v->pscl_throughput[k] / (v->return_bw / v->dpp_per_plane[k]), v->effective_lb_latency_hiding_source_lines_luma), v->swath_height_y[k]); 1429 v->urgent_latency_support_us_luma = v->effective_det_plus_lb_lines_luma * (v->htotal[k] / v->pixel_clock[k]) / v->v_ratio[k] - v->effective_det_plus_lb_lines_luma * v->swath_width_y[k] * v->byte_per_pixel_dety[k] / (v->return_bw / v->dpp_per_plane[k]); 1430 if (v->byte_per_pixel_detc[k] > 0.0) { 1431 v->effective_det_plus_lb_lines_chroma =dcn_bw_floor2(v->lines_in_detc[k] +dcn_bw_min2(v->lines_in_detc[k] * v->dppclk * v->byte_per_pixel_detc[k] * v->pscl_throughput_chroma[k] / (v->return_bw / v->dpp_per_plane[k]), v->effective_lb_latency_hiding_source_lines_chroma), v->swath_height_c[k]); 1432 v->urgent_latency_support_us_chroma = v->effective_det_plus_lb_lines_chroma * (v->htotal[k] / v->pixel_clock[k]) / (v->v_ratio[k] / 2.0) - v->effective_det_plus_lb_lines_chroma * (v->swath_width_y[k] / 2.0) * v->byte_per_pixel_detc[k] / (v->return_bw / v->dpp_per_plane[k]); 1433 v->urgent_latency_support_us[k] =dcn_bw_min2(v->urgent_latency_support_us_luma, v->urgent_latency_support_us_chroma); 1434 } 1435 else { 1436 v->urgent_latency_support_us[k] = v->urgent_latency_support_us_luma; 1437 } 1438 } 1439 v->min_urgent_latency_support_us = 999999.0; 1440 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1441 v->min_urgent_latency_support_us =dcn_bw_min2(v->min_urgent_latency_support_us, v->urgent_latency_support_us[k]); 1442 } 1443 /*non-urgent latency tolerance*/ 1444 1445 v->non_urgent_latency_tolerance = v->min_urgent_latency_support_us - v->urgent_watermark; 1446 /*prefetch*/ 1447 1448 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1449 if ((v->source_pixel_format[k] == dcn_bw_rgb_sub_64 || v->source_pixel_format[k] == dcn_bw_rgb_sub_32 || v->source_pixel_format[k] == dcn_bw_rgb_sub_16)) { 1450 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1451 v->block_height256_bytes_y = 1.0; 1452 } 1453 else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) { 1454 v->block_height256_bytes_y = 4.0; 1455 } 1456 else { 1457 v->block_height256_bytes_y = 8.0; 1458 } 1459 v->block_height256_bytes_c = 0.0; 1460 } 1461 else { 1462 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1463 v->block_height256_bytes_y = 1.0; 1464 v->block_height256_bytes_c = 1.0; 1465 } 1466 else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) { 1467 v->block_height256_bytes_y = 16.0; 1468 v->block_height256_bytes_c = 8.0; 1469 } 1470 else { 1471 v->block_height256_bytes_y = 8.0; 1472 v->block_height256_bytes_c = 8.0; 1473 } 1474 } 1475 if (v->dcc_enable[k] == dcn_bw_yes) { 1476 v->meta_request_width_y = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / (8.0 * v->block_height256_bytes_y); 1477 v->meta_surf_width_y =dcn_bw_ceil2(v->swath_width_y[k] - 1.0, v->meta_request_width_y) + v->meta_request_width_y; 1478 v->meta_surf_height_y =dcn_bw_ceil2(v->viewport_height[k] - 1.0, 8.0 * v->block_height256_bytes_y) + 8.0 * v->block_height256_bytes_y; 1479 if (v->pte_enable == dcn_bw_yes) { 1480 v->meta_pte_bytes_frame_y = (dcn_bw_ceil2((v->meta_surf_width_y * v->meta_surf_height_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0; 1481 } 1482 else { 1483 v->meta_pte_bytes_frame_y = 0.0; 1484 } 1485 if (v->source_scan[k] == dcn_bw_hor) { 1486 v->meta_row_byte_y = v->meta_surf_width_y * 8.0 * v->block_height256_bytes_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0; 1487 } 1488 else { 1489 v->meta_row_byte_y = v->meta_surf_height_y * v->meta_request_width_y *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / 256.0; 1490 } 1491 } 1492 else { 1493 v->meta_pte_bytes_frame_y = 0.0; 1494 v->meta_row_byte_y = 0.0; 1495 } 1496 if (v->pte_enable == dcn_bw_yes) { 1497 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1498 v->macro_tile_size_byte_y = 256.0; 1499 v->macro_tile_height_y = 1.0; 1500 } 1501 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) { 1502 v->macro_tile_size_byte_y = 4096.0; 1503 v->macro_tile_height_y = 4.0 * v->block_height256_bytes_y; 1504 } 1505 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) { 1506 v->macro_tile_size_byte_y = 64.0 * 1024; 1507 v->macro_tile_height_y = 16.0 * v->block_height256_bytes_y; 1508 } 1509 else { 1510 v->macro_tile_size_byte_y = 256.0 * 1024; 1511 v->macro_tile_height_y = 32.0 * v->block_height256_bytes_y; 1512 } 1513 if (v->macro_tile_size_byte_y <= 65536.0) { 1514 v->pixel_pte_req_height_y = v->macro_tile_height_y; 1515 } 1516 else { 1517 v->pixel_pte_req_height_y = 16.0 * v->block_height256_bytes_y; 1518 } 1519 v->pixel_pte_req_width_y = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) / v->pixel_pte_req_height_y * 8; 1520 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1521 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] *dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->pixel_pte_req_width_y / v->swath_width_y[k], 2.0), 1.0))) - 1.0) / v->pixel_pte_req_width_y, 1.0) + 1); 1522 } 1523 else if (v->source_scan[k] == dcn_bw_hor) { 1524 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] - 1.0) / v->pixel_pte_req_width_y, 1.0) + 1); 1525 } 1526 else { 1527 v->pixel_pte_bytes_per_row_y = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] - 1.0) / v->pixel_pte_req_height_y, 1.0) + 1); 1528 } 1529 } 1530 else { 1531 v->pixel_pte_bytes_per_row_y = 0.0; 1532 } 1533 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) { 1534 if (v->dcc_enable[k] == dcn_bw_yes) { 1535 v->meta_request_width_c = 64.0 * 256.0 /dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / (8.0 * v->block_height256_bytes_c); 1536 v->meta_surf_width_c =dcn_bw_ceil2(v->swath_width_y[k] / 2.0 - 1.0, v->meta_request_width_c) + v->meta_request_width_c; 1537 v->meta_surf_height_c =dcn_bw_ceil2(v->viewport_height[k] / 2.0 - 1.0, 8.0 * v->block_height256_bytes_c) + 8.0 * v->block_height256_bytes_c; 1538 if (v->pte_enable == dcn_bw_yes) { 1539 v->meta_pte_bytes_frame_c = (dcn_bw_ceil2((v->meta_surf_width_c * v->meta_surf_height_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0 - 4096.0) / 8.0 / 4096.0, 1.0) + 1) * 64.0; 1540 } 1541 else { 1542 v->meta_pte_bytes_frame_c = 0.0; 1543 } 1544 if (v->source_scan[k] == dcn_bw_hor) { 1545 v->meta_row_byte_c = v->meta_surf_width_c * 8.0 * v->block_height256_bytes_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0; 1546 } 1547 else { 1548 v->meta_row_byte_c = v->meta_surf_height_c * v->meta_request_width_c *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 256.0; 1549 } 1550 } 1551 else { 1552 v->meta_pte_bytes_frame_c = 0.0; 1553 v->meta_row_byte_c = 0.0; 1554 } 1555 if (v->pte_enable == dcn_bw_yes) { 1556 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1557 v->macro_tile_size_bytes_c = 256.0; 1558 v->macro_tile_height_c = 1.0; 1559 } 1560 else if (v->source_surface_mode[k] == dcn_bw_sw_4_kb_s || v->source_surface_mode[k] == dcn_bw_sw_4_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d || v->source_surface_mode[k] == dcn_bw_sw_4_kb_d_x) { 1561 v->macro_tile_size_bytes_c = 4096.0; 1562 v->macro_tile_height_c = 4.0 * v->block_height256_bytes_c; 1563 } 1564 else if (v->source_surface_mode[k] == dcn_bw_sw_64_kb_s || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_s_x || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_t || v->source_surface_mode[k] == dcn_bw_sw_64_kb_d_x) { 1565 v->macro_tile_size_bytes_c = 64.0 * 1024; 1566 v->macro_tile_height_c = 16.0 * v->block_height256_bytes_c; 1567 } 1568 else { 1569 v->macro_tile_size_bytes_c = 256.0 * 1024; 1570 v->macro_tile_height_c = 32.0 * v->block_height256_bytes_c; 1571 } 1572 if (v->macro_tile_size_bytes_c <= 65536.0) { 1573 v->pixel_pte_req_height_c = v->macro_tile_height_c; 1574 } 1575 else { 1576 v->pixel_pte_req_height_c = 16.0 * v->block_height256_bytes_c; 1577 } 1578 v->pixel_pte_req_width_c = 4096.0 /dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / v->pixel_pte_req_height_c * 8; 1579 if (v->source_surface_mode[k] == dcn_bw_sw_linear) { 1580 v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] / 2.0 * dcn_bw_min2(128.0, dcn_bw_pow(2.0,dcn_bw_floor2(dcn_bw_log(v->pte_buffer_size_in_requests * v->pixel_pte_req_width_c / (v->swath_width_y[k] / 2.0), 2.0), 1.0))) - 1.0) / v->pixel_pte_req_width_c, 1.0) + 1); 1581 } 1582 else if (v->source_scan[k] == dcn_bw_hor) { 1583 v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->swath_width_y[k] / 2.0 - 1.0) / v->pixel_pte_req_width_c, 1.0) + 1); 1584 } 1585 else { 1586 v->pixel_pte_bytes_per_row_c = 64.0 * (dcn_bw_ceil2((v->viewport_height[k] / 2.0 - 1.0) / v->pixel_pte_req_height_c, 1.0) + 1); 1587 } 1588 } 1589 else { 1590 v->pixel_pte_bytes_per_row_c = 0.0; 1591 } 1592 } 1593 else { 1594 v->pixel_pte_bytes_per_row_c = 0.0; 1595 v->meta_pte_bytes_frame_c = 0.0; 1596 v->meta_row_byte_c = 0.0; 1597 } 1598 v->pixel_pte_bytes_per_row[k] = v->pixel_pte_bytes_per_row_y + v->pixel_pte_bytes_per_row_c; 1599 v->meta_pte_bytes_frame[k] = v->meta_pte_bytes_frame_y + v->meta_pte_bytes_frame_c; 1600 v->meta_row_byte[k] = v->meta_row_byte_y + v->meta_row_byte_c; 1601 v->v_init_pre_fill_y[k] =dcn_bw_floor2((v->v_ratio[k] + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k]) / 2.0, 1.0); 1602 v->max_num_swath_y[k] =dcn_bw_ceil2((v->v_init_pre_fill_y[k] - 1.0) / v->swath_height_y[k], 1.0) + 1; 1603 if (v->v_init_pre_fill_y[k] > 1.0) { 1604 v->max_partial_swath_y =dcn_bw_mod((v->v_init_pre_fill_y[k] - 2.0), v->swath_height_y[k]); 1605 } 1606 else { 1607 v->max_partial_swath_y =dcn_bw_mod((v->v_init_pre_fill_y[k] + v->swath_height_y[k] - 2.0), v->swath_height_y[k]); 1608 } 1609 v->max_partial_swath_y =dcn_bw_max2(1.0, v->max_partial_swath_y); 1610 v->prefetch_source_lines_y[k] = v->max_num_swath_y[k] * v->swath_height_y[k] + v->max_partial_swath_y; 1611 if ((v->source_pixel_format[k] != dcn_bw_rgb_sub_64 && v->source_pixel_format[k] != dcn_bw_rgb_sub_32 && v->source_pixel_format[k] != dcn_bw_rgb_sub_16)) { 1612 v->v_init_pre_fill_c[k] =dcn_bw_floor2((v->v_ratio[k] / 2.0 + v->vtaps[k] + 1.0 + v->interlace_output[k] * 0.5 * v->v_ratio[k] / 2.0) / 2.0, 1.0); 1613 v->max_num_swath_c[k] =dcn_bw_ceil2((v->v_init_pre_fill_c[k] - 1.0) / v->swath_height_c[k], 1.0) + 1; 1614 if (v->v_init_pre_fill_c[k] > 1.0) { 1615 v->max_partial_swath_c =dcn_bw_mod((v->v_init_pre_fill_c[k] - 2.0), v->swath_height_c[k]); 1616 } 1617 else { 1618 v->max_partial_swath_c =dcn_bw_mod((v->v_init_pre_fill_c[k] + v->swath_height_c[k] - 2.0), v->swath_height_c[k]); 1619 } 1620 v->max_partial_swath_c =dcn_bw_max2(1.0, v->max_partial_swath_c); 1621 } 1622 else { 1623 v->max_num_swath_c[k] = 0.0; 1624 v->max_partial_swath_c = 0.0; 1625 } 1626 v->prefetch_source_lines_c[k] = v->max_num_swath_c[k] * v->swath_height_c[k] + v->max_partial_swath_c; 1627 } 1628 v->t_calc = 24.0 / v->dcf_clk_deep_sleep; 1629 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1630 if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) { 1631 v->max_vstartup_lines[k] = v->vtotal[k] - v->vactive[k] - 1.0; 1632 } 1633 else { 1634 v->max_vstartup_lines[k] = v->v_sync_plus_back_porch[k] - 1.0; 1635 } 1636 } 1637 v->next_prefetch_mode = 0.0; 1638 do { 1639 v->v_startup_lines = 13.0; 1640 do { 1641 v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_yes; 1642 v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_no; 1643 v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_no; 1644 v->v_ratio_prefetch_more_than4 = dcn_bw_no; 1645 v->destination_line_times_for_prefetch_less_than2 = dcn_bw_no; 1646 v->prefetch_mode = v->next_prefetch_mode; 1647 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1648 v->dstx_after_scaler = 90.0 * v->pixel_clock[k] / v->dppclk + 42.0 * v->pixel_clock[k] / v->dispclk; 1649 if (v->dpp_per_plane[k] > 1.0) { 1650 v->dstx_after_scaler = v->dstx_after_scaler + v->scaler_rec_out_width[k] / 2.0; 1651 } 1652 if (v->output_format[k] == dcn_bw_420) { 1653 v->dsty_after_scaler = 1.0; 1654 } 1655 else { 1656 v->dsty_after_scaler = 0.0; 1657 } 1658 v->v_update_offset_pix[k] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0); 1659 v->total_repeater_delay_time = v->max_inter_dcn_tile_repeaters * (2.0 / v->dppclk + 3.0 / v->dispclk); 1660 v->v_update_width_pix[k] = (14.0 / v->dcf_clk_deep_sleep + 12.0 / v->dppclk + v->total_repeater_delay_time) * v->pixel_clock[k]; 1661 v->v_ready_offset_pix[k] = dcn_bw_max2(150.0 / v->dppclk, v->total_repeater_delay_time + 20.0 / v->dcf_clk_deep_sleep + 10.0 / v->dppclk) * v->pixel_clock[k]; 1662 v->t_setup = (v->v_update_offset_pix[k] + v->v_update_width_pix[k] + v->v_ready_offset_pix[k]) / v->pixel_clock[k]; 1663 v->v_startup[k] =dcn_bw_min2(v->v_startup_lines, v->max_vstartup_lines[k]); 1664 if (v->prefetch_mode == 0.0) { 1665 v->t_wait =dcn_bw_max3(v->dram_clock_change_latency + v->urgent_latency, v->sr_enter_plus_exit_time, v->urgent_latency); 1666 } 1667 else if (v->prefetch_mode == 1.0) { 1668 v->t_wait =dcn_bw_max2(v->sr_enter_plus_exit_time, v->urgent_latency); 1669 } 1670 else { 1671 v->t_wait = v->urgent_latency; 1672 } 1673 v->destination_lines_for_prefetch[k] =dcn_bw_floor2(4.0 * (v->v_startup[k] - v->t_wait / (v->htotal[k] / v->pixel_clock[k]) - (v->t_calc + v->t_setup) / (v->htotal[k] / v->pixel_clock[k]) - (v->dsty_after_scaler + v->dstx_after_scaler / v->htotal[k]) + 0.125), 1.0) / 4; 1674 if (v->destination_lines_for_prefetch[k] > 0.0) { 1675 v->prefetch_bandwidth[k] = (v->meta_pte_bytes_frame[k] + 2.0 * v->meta_row_byte[k] + 2.0 * v->pixel_pte_bytes_per_row[k] + v->prefetch_source_lines_y[k] * v->swath_width_y[k] *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) + v->prefetch_source_lines_c[k] * v->swath_width_y[k] / 2.0 *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0)) / (v->destination_lines_for_prefetch[k] * v->htotal[k] / v->pixel_clock[k]); 1676 } 1677 else { 1678 v->prefetch_bandwidth[k] = 999999.0; 1679 } 1680 } 1681 v->bandwidth_available_for_immediate_flip = v->return_bw; 1682 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1683 v->bandwidth_available_for_immediate_flip = v->bandwidth_available_for_immediate_flip -dcn_bw_max2(v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k], v->prefetch_bandwidth[k]); 1684 } 1685 v->tot_immediate_flip_bytes = 0.0; 1686 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1687 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 1688 v->tot_immediate_flip_bytes = v->tot_immediate_flip_bytes + v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]; 1689 } 1690 } 1691 v->max_rd_bandwidth = 0.0; 1692 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1693 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) { 1694 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 1695 v->time_for_fetching_meta_pte =dcn_bw_max5(v->meta_pte_bytes_frame[k] / v->prefetch_bandwidth[k], v->meta_pte_bytes_frame[k] * v->tot_immediate_flip_bytes / (v->bandwidth_available_for_immediate_flip * (v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k])), v->urgent_extra_latency, v->urgent_latency, v->htotal[k] / v->pixel_clock[k] / 4.0); 1696 } 1697 else { 1698 v->time_for_fetching_meta_pte =dcn_bw_max3(v->meta_pte_bytes_frame[k] / v->prefetch_bandwidth[k], v->urgent_extra_latency, v->htotal[k] / v->pixel_clock[k] / 4.0); 1699 } 1700 } 1701 else { 1702 v->time_for_fetching_meta_pte = v->htotal[k] / v->pixel_clock[k] / 4.0; 1703 } 1704 v->destination_lines_to_request_vm_inv_blank[k] =dcn_bw_floor2(4.0 * (v->time_for_fetching_meta_pte / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 1705 if ((v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes)) { 1706 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 1707 v->time_for_fetching_row_in_vblank =dcn_bw_max5((v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / v->prefetch_bandwidth[k], (v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) * v->tot_immediate_flip_bytes / (v->bandwidth_available_for_immediate_flip * (v->meta_pte_bytes_frame[k] + v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k])), v->urgent_extra_latency, 2.0 * v->urgent_latency, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte); 1708 } 1709 else { 1710 v->time_for_fetching_row_in_vblank =dcn_bw_max3((v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / v->prefetch_bandwidth[k], v->urgent_extra_latency, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte); 1711 } 1712 } 1713 else { 1714 v->time_for_fetching_row_in_vblank =dcn_bw_max2(v->urgent_extra_latency - v->time_for_fetching_meta_pte, v->htotal[k] / v->pixel_clock[k] - v->time_for_fetching_meta_pte); 1715 } 1716 v->destination_lines_to_request_row_in_vblank[k] =dcn_bw_floor2(4.0 * (v->time_for_fetching_row_in_vblank / (v->htotal[k] / v->pixel_clock[k]) + 0.125), 1.0) / 4; 1717 v->lines_to_request_prefetch_pixel_data = v->destination_lines_for_prefetch[k] - v->destination_lines_to_request_vm_inv_blank[k] - v->destination_lines_to_request_row_in_vblank[k]; 1718 if (v->lines_to_request_prefetch_pixel_data > 0.0) { 1719 v->v_ratio_prefetch_y[k] = v->prefetch_source_lines_y[k] / v->lines_to_request_prefetch_pixel_data; 1720 if ((v->swath_height_y[k] > 4.0)) { 1721 if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_y[k] - 3.0) / 2.0) { 1722 v->v_ratio_prefetch_y[k] =dcn_bw_max2(v->v_ratio_prefetch_y[k], v->max_num_swath_y[k] * v->swath_height_y[k] / (v->lines_to_request_prefetch_pixel_data - (v->v_init_pre_fill_y[k] - 3.0) / 2.0)); 1723 } 1724 else { 1725 v->v_ratio_prefetch_y[k] = 999999.0; 1726 } 1727 } 1728 } 1729 else { 1730 v->v_ratio_prefetch_y[k] = 999999.0; 1731 } 1732 v->v_ratio_prefetch_y[k] =dcn_bw_max2(v->v_ratio_prefetch_y[k], 1.0); 1733 if (v->lines_to_request_prefetch_pixel_data > 0.0) { 1734 v->v_ratio_prefetch_c[k] = v->prefetch_source_lines_c[k] / v->lines_to_request_prefetch_pixel_data; 1735 if ((v->swath_height_c[k] > 4.0)) { 1736 if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_c[k] - 3.0) / 2.0) { 1737 v->v_ratio_prefetch_c[k] =dcn_bw_max2(v->v_ratio_prefetch_c[k], v->max_num_swath_c[k] * v->swath_height_c[k] / (v->lines_to_request_prefetch_pixel_data - (v->v_init_pre_fill_c[k] - 3.0) / 2.0)); 1738 } 1739 else { 1740 v->v_ratio_prefetch_c[k] = 999999.0; 1741 } 1742 } 1743 } 1744 else { 1745 v->v_ratio_prefetch_c[k] = 999999.0; 1746 } 1747 v->v_ratio_prefetch_c[k] =dcn_bw_max2(v->v_ratio_prefetch_c[k], 1.0); 1748 if (v->lines_to_request_prefetch_pixel_data > 0.0) { 1749 v->required_prefetch_pix_data_bw = v->dpp_per_plane[k] * (v->prefetch_source_lines_y[k] / v->lines_to_request_prefetch_pixel_data *dcn_bw_ceil2(v->byte_per_pixel_dety[k], 1.0) + v->prefetch_source_lines_c[k] / v->lines_to_request_prefetch_pixel_data *dcn_bw_ceil2(v->byte_per_pixel_detc[k], 2.0) / 2.0) * v->swath_width_y[k] / (v->htotal[k] / v->pixel_clock[k]); 1750 } 1751 else { 1752 v->required_prefetch_pix_data_bw = 999999.0; 1753 } 1754 v->max_rd_bandwidth = v->max_rd_bandwidth +dcn_bw_max2(v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k], v->required_prefetch_pix_data_bw); 1755 if (v->immediate_flip_supported == dcn_bw_yes && (v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) { 1756 v->max_rd_bandwidth = v->max_rd_bandwidth +dcn_bw_max2(v->meta_pte_bytes_frame[k] / (v->destination_lines_to_request_vm_inv_blank[k] * v->htotal[k] / v->pixel_clock[k]), (v->meta_row_byte[k] + v->pixel_pte_bytes_per_row[k]) / (v->destination_lines_to_request_row_in_vblank[k] * v->htotal[k] / v->pixel_clock[k])); 1757 } 1758 if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) { 1759 v->v_ratio_prefetch_more_than4 = dcn_bw_yes; 1760 } 1761 if (v->destination_lines_for_prefetch[k] < 2.0) { 1762 v->destination_line_times_for_prefetch_less_than2 = dcn_bw_yes; 1763 } 1764 if (v->max_vstartup_lines[k] > v->v_startup_lines) { 1765 if (v->required_prefetch_pix_data_bw > (v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k])) { 1766 v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_no; 1767 } 1768 if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) { 1769 v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_yes; 1770 } 1771 if (v->destination_lines_for_prefetch[k] < 2.0) { 1772 v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_yes; 1773 } 1774 } 1775 } 1776 if (v->max_rd_bandwidth <= v->return_bw && v->v_ratio_prefetch_more_than4 == dcn_bw_no && v->destination_line_times_for_prefetch_less_than2 == dcn_bw_no) { 1777 v->prefetch_mode_supported = dcn_bw_yes; 1778 } 1779 else { 1780 v->prefetch_mode_supported = dcn_bw_no; 1781 } 1782 v->v_startup_lines = v->v_startup_lines + 1.0; 1783 } while (!(v->prefetch_mode_supported == dcn_bw_yes || (v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw == dcn_bw_yes && v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 == dcn_bw_no && v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 == dcn_bw_no))); 1784 v->next_prefetch_mode = v->next_prefetch_mode + 1.0; 1785 } while (!(v->prefetch_mode_supported == dcn_bw_yes || v->prefetch_mode == 2.0)); 1786 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1787 if (v->v_ratio_prefetch_y[k] <= 1.0) { 1788 v->display_pipe_line_delivery_time_luma_prefetch[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k]; 1789 } 1790 else { 1791 v->display_pipe_line_delivery_time_luma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk; 1792 } 1793 if (v->byte_per_pixel_detc[k] == 0.0) { 1794 v->display_pipe_line_delivery_time_chroma_prefetch[k] = 0.0; 1795 } 1796 else { 1797 if (v->v_ratio_prefetch_c[k] <= 1.0) { 1798 v->display_pipe_line_delivery_time_chroma_prefetch[k] = v->swath_width_y[k] * v->dpp_per_plane[k] / v->h_ratio[k] / v->pixel_clock[k]; 1799 } 1800 else { 1801 v->display_pipe_line_delivery_time_chroma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk; 1802 } 1803 } 1804 } 1805 /*min ttuv_blank*/ 1806 1807 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1808 if (v->prefetch_mode == 0.0) { 1809 v->allow_dram_clock_change_during_vblank[k] = dcn_bw_yes; 1810 v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes; 1811 v->min_ttuv_blank[k] = v->t_calc +dcn_bw_max3(v->dram_clock_change_watermark, v->stutter_enter_plus_exit_watermark, v->urgent_watermark); 1812 } 1813 else if (v->prefetch_mode == 1.0) { 1814 v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no; 1815 v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes; 1816 v->min_ttuv_blank[k] = v->t_calc +dcn_bw_max2(v->stutter_enter_plus_exit_watermark, v->urgent_watermark); 1817 } 1818 else { 1819 v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no; 1820 v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_no; 1821 v->min_ttuv_blank[k] = v->t_calc + v->urgent_watermark; 1822 } 1823 } 1824 /*nb p-state/dram clock change support*/ 1825 1826 v->active_dp_ps = 0.0; 1827 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1828 v->active_dp_ps = v->active_dp_ps + v->dpp_per_plane[k]; 1829 } 1830 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1831 v->lb_latency_hiding_source_lines_y =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_y[k] /dcn_bw_max2(v->h_ratio[k], 1.0)), 1.0)) - (v->vtaps[k] - 1.0); 1832 v->lb_latency_hiding_source_lines_c =dcn_bw_min2(v->max_line_buffer_lines,dcn_bw_floor2(v->line_buffer_size / v->lb_bit_per_pixel[k] / (v->swath_width_y[k] / 2.0 /dcn_bw_max2(v->h_ratio[k] / 2.0, 1.0)), 1.0)) - (v->vta_pschroma[k] - 1.0); 1833 v->effective_lb_latency_hiding_y = v->lb_latency_hiding_source_lines_y / v->v_ratio[k] * (v->htotal[k] / v->pixel_clock[k]); 1834 v->effective_lb_latency_hiding_c = v->lb_latency_hiding_source_lines_c / (v->v_ratio[k] / 2.0) * (v->htotal[k] / v->pixel_clock[k]); 1835 if (v->swath_width_y[k] > 2.0 * v->dpp_output_buffer_pixels) { 1836 v->dpp_output_buffer_lines_y = v->dpp_output_buffer_pixels / v->swath_width_y[k]; 1837 } 1838 else if (v->swath_width_y[k] > v->dpp_output_buffer_pixels) { 1839 v->dpp_output_buffer_lines_y = 0.5; 1840 } 1841 else { 1842 v->dpp_output_buffer_lines_y = 1.0; 1843 } 1844 if (v->swath_width_y[k] / 2.0 > 2.0 * v->dpp_output_buffer_pixels) { 1845 v->dpp_output_buffer_lines_c = v->dpp_output_buffer_pixels / (v->swath_width_y[k] / 2.0); 1846 } 1847 else if (v->swath_width_y[k] / 2.0 > v->dpp_output_buffer_pixels) { 1848 v->dpp_output_buffer_lines_c = 0.5; 1849 } 1850 else { 1851 v->dpp_output_buffer_lines_c = 1.0; 1852 } 1853 v->dppopp_buffering_y = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_y + v->opp_output_buffer_lines); 1854 v->max_det_buffering_time_y = v->full_det_buffering_time_y[k] + (v->lines_in_dety[k] - v->lines_in_dety_rounded_down_to_swath[k]) / v->swath_height_y[k] * (v->htotal[k] / v->pixel_clock[k]); 1855 v->active_dram_clock_change_latency_margin_y = v->dppopp_buffering_y + v->effective_lb_latency_hiding_y + v->max_det_buffering_time_y - v->dram_clock_change_watermark; 1856 if (v->active_dp_ps > 1.0) { 1857 v->active_dram_clock_change_latency_margin_y = v->active_dram_clock_change_latency_margin_y - (1.0 - 1.0 / (v->active_dp_ps - 1.0)) * v->swath_height_y[k] * (v->htotal[k] / v->pixel_clock[k]); 1858 } 1859 if (v->byte_per_pixel_detc[k] > 0.0) { 1860 v->dppopp_buffering_c = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_c + v->opp_output_buffer_lines); 1861 v->max_det_buffering_time_c = v->full_det_buffering_time_c[k] + (v->lines_in_detc[k] - v->lines_in_detc_rounded_down_to_swath[k]) / v->swath_height_c[k] * (v->htotal[k] / v->pixel_clock[k]); 1862 v->active_dram_clock_change_latency_margin_c = v->dppopp_buffering_c + v->effective_lb_latency_hiding_c + v->max_det_buffering_time_c - v->dram_clock_change_watermark; 1863 if (v->active_dp_ps > 1.0) { 1864 v->active_dram_clock_change_latency_margin_c = v->active_dram_clock_change_latency_margin_c - (1.0 - 1.0 / (v->active_dp_ps - 1.0)) * v->swath_height_c[k] * (v->htotal[k] / v->pixel_clock[k]); 1865 } 1866 v->active_dram_clock_change_latency_margin[k] =dcn_bw_min2(v->active_dram_clock_change_latency_margin_y, v->active_dram_clock_change_latency_margin_c); 1867 } 1868 else { 1869 v->active_dram_clock_change_latency_margin[k] = v->active_dram_clock_change_latency_margin_y; 1870 } 1871 if (v->output_format[k] == dcn_bw_444) { 1872 v->writeback_dram_clock_change_latency_margin = (v->writeback_luma_buffer_size + v->writeback_chroma_buffer_size) * 1024.0 / (v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0) - v->writeback_dram_clock_change_watermark; 1873 } 1874 else { 1875 v->writeback_dram_clock_change_latency_margin =dcn_bw_min2(v->writeback_luma_buffer_size, 2.0 * v->writeback_chroma_buffer_size) * 1024.0 / (v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k])) - v->writeback_dram_clock_change_watermark; 1876 } 1877 if (v->output[k] == dcn_bw_writeback) { 1878 v->active_dram_clock_change_latency_margin[k] =dcn_bw_min2(v->active_dram_clock_change_latency_margin[k], v->writeback_dram_clock_change_latency_margin); 1879 } 1880 } 1881 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1882 if (v->allow_dram_clock_change_during_vblank[k] == dcn_bw_yes) { 1883 v->v_blank_dram_clock_change_latency_margin[k] = (v->vtotal[k] - v->scaler_recout_height[k]) * (v->htotal[k] / v->pixel_clock[k]) -dcn_bw_max2(v->dram_clock_change_watermark, v->writeback_dram_clock_change_watermark); 1884 } 1885 else { 1886 v->v_blank_dram_clock_change_latency_margin[k] = 0.0; 1887 } 1888 } 1889 v->min_active_dram_clock_change_margin = 999999.0; 1890 v->v_blank_of_min_active_dram_clock_change_margin = 999999.0; 1891 v->second_min_active_dram_clock_change_margin = 999999.0; 1892 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1893 if (v->active_dram_clock_change_latency_margin[k] < v->min_active_dram_clock_change_margin) { 1894 v->second_min_active_dram_clock_change_margin = v->min_active_dram_clock_change_margin; 1895 v->min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k]; 1896 v->v_blank_of_min_active_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k]; 1897 } 1898 else if (v->active_dram_clock_change_latency_margin[k] < v->second_min_active_dram_clock_change_margin) { 1899 v->second_min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k]; 1900 } 1901 } 1902 v->min_vblank_dram_clock_change_margin = 999999.0; 1903 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1904 if (v->min_vblank_dram_clock_change_margin > v->v_blank_dram_clock_change_latency_margin[k]) { 1905 v->min_vblank_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k]; 1906 } 1907 } 1908 if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) { 1909 v->dram_clock_change_margin =dcn_bw_max2(v->min_active_dram_clock_change_margin, v->min_vblank_dram_clock_change_margin); 1910 } 1911 else if (v->v_blank_of_min_active_dram_clock_change_margin > v->min_active_dram_clock_change_margin) { 1912 v->dram_clock_change_margin =dcn_bw_min2(v->second_min_active_dram_clock_change_margin, v->v_blank_of_min_active_dram_clock_change_margin); 1913 } 1914 else { 1915 v->dram_clock_change_margin = v->min_active_dram_clock_change_margin; 1916 } 1917 if (v->min_active_dram_clock_change_margin > 0.0) { 1918 v->dram_clock_change_support = dcn_bw_supported_in_v_active; 1919 } 1920 else if (v->dram_clock_change_margin > 0.0) { 1921 v->dram_clock_change_support = dcn_bw_supported_in_v_blank; 1922 } 1923 else { 1924 v->dram_clock_change_support = dcn_bw_not_supported; 1925 } 1926 /*maximum bandwidth used*/ 1927 1928 v->wr_bandwidth = 0.0; 1929 for (k = 0; k <= v->number_of_active_planes - 1; k++) { 1930 if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) { 1931 v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0; 1932 } 1933 else if (v->output[k] == dcn_bw_writeback) { 1934 v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5; 1935 } 1936 } 1937 v->max_used_bw = v->max_rd_bandwidth + v->wr_bandwidth; 1938 } 1939