Linux Audio

Check our new training course

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