Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2017 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #include "dm_services.h"
0027 #include "dcn_calc_auto.h"
0028 #include "dcn_calc_math.h"
0029 
0030 /*
0031  * NOTE:
0032  *   This file is gcc-parseable HW gospel, coming straight from HW engineers.
0033  *
0034  * It doesn't adhere to Linux kernel style and sometimes will do things in odd
0035  * ways. Unless there is something clearly wrong with it the code should
0036  * remain as-is as it provides us with a guarantee from HW that it is correct.
0037  */
0038 
0039 /*REVISION#250*/
0040 void scaler_settings_calculation(struct dcn_bw_internal_vars *v)
0041 {
0042     int k;
0043     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0044         if (v->allow_different_hratio_vratio == dcn_bw_yes) {
0045             if (v->source_scan[k] == dcn_bw_hor) {
0046                 v->h_ratio[k] = v->viewport_width[k] / v->scaler_rec_out_width[k];
0047                 v->v_ratio[k] = v->viewport_height[k] / v->scaler_recout_height[k];
0048             }
0049             else {
0050                 v->h_ratio[k] = v->viewport_height[k] / v->scaler_rec_out_width[k];
0051                 v->v_ratio[k] = v->viewport_width[k] / v->scaler_recout_height[k];
0052             }
0053         }
0054         else {
0055             if (v->source_scan[k] == dcn_bw_hor) {
0056                 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]);
0057             }
0058             else {
0059                 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]);
0060             }
0061             v->v_ratio[k] = v->h_ratio[k];
0062         }
0063         if (v->interlace_output[k] == 1.0) {
0064             v->v_ratio[k] = 2.0 * v->v_ratio[k];
0065         }
0066         if (v->underscan_output[k] == 1.0) {
0067             v->h_ratio[k] = v->h_ratio[k] * v->under_scan_factor;
0068             v->v_ratio[k] = v->v_ratio[k] * v->under_scan_factor;
0069         }
0070     }
0071     /*scaler taps calculation*/
0072 
0073     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0074         if (v->h_ratio[k] > 1.0) {
0075             v->acceptable_quality_hta_ps =dcn_bw_min2(v->max_hscl_taps, 2.0 *dcn_bw_ceil2(v->h_ratio[k], 1.0));
0076         }
0077         else if (v->h_ratio[k] < 1.0) {
0078             v->acceptable_quality_hta_ps = 4.0;
0079         }
0080         else {
0081             v->acceptable_quality_hta_ps = 1.0;
0082         }
0083         if (v->ta_pscalculation == dcn_bw_override) {
0084             v->htaps[k] = v->override_hta_ps[k];
0085         }
0086         else {
0087             v->htaps[k] = v->acceptable_quality_hta_ps;
0088         }
0089         if (v->v_ratio[k] > 1.0) {
0090             v->acceptable_quality_vta_ps =dcn_bw_min2(v->max_vscl_taps, 2.0 *dcn_bw_ceil2(v->v_ratio[k], 1.0));
0091         }
0092         else if (v->v_ratio[k] < 1.0) {
0093             v->acceptable_quality_vta_ps = 4.0;
0094         }
0095         else {
0096             v->acceptable_quality_vta_ps = 1.0;
0097         }
0098         if (v->ta_pscalculation == dcn_bw_override) {
0099             v->vtaps[k] = v->override_vta_ps[k];
0100         }
0101         else {
0102             v->vtaps[k] = v->acceptable_quality_vta_ps;
0103         }
0104         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) {
0105             v->vta_pschroma[k] = 0.0;
0106             v->hta_pschroma[k] = 0.0;
0107         }
0108         else {
0109             if (v->ta_pscalculation == dcn_bw_override) {
0110                 v->vta_pschroma[k] = v->override_vta_pschroma[k];
0111                 v->hta_pschroma[k] = v->override_hta_pschroma[k];
0112             }
0113             else {
0114                 v->vta_pschroma[k] = v->acceptable_quality_vta_ps;
0115                 v->hta_pschroma[k] = v->acceptable_quality_hta_ps;
0116             }
0117         }
0118     }
0119 }
0120 
0121 void mode_support_and_system_configuration(struct dcn_bw_internal_vars *v)
0122 {
0123     int i;
0124     int j;
0125     int k;
0126     /*mode support, voltage state and soc configuration*/
0127 
0128     /*scale ratio support check*/
0129 
0130     v->scale_ratio_support = dcn_bw_yes;
0131     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0132         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]))) {
0133             v->scale_ratio_support = dcn_bw_no;
0134         }
0135     }
0136     /*source format, pixel format and scan support check*/
0137 
0138     v->source_format_pixel_and_scan_support = dcn_bw_yes;
0139     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0140         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)) {
0141             v->source_format_pixel_and_scan_support = dcn_bw_no;
0142         }
0143     }
0144     /*bandwidth support check*/
0145 
0146     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0147         if (v->source_scan[k] == dcn_bw_hor) {
0148             v->swath_width_ysingle_dpp[k] = v->viewport_width[k];
0149         }
0150         else {
0151             v->swath_width_ysingle_dpp[k] = v->viewport_height[k];
0152         }
0153         if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
0154             v->byte_per_pixel_in_dety[k] = 8.0;
0155             v->byte_per_pixel_in_detc[k] = 0.0;
0156         }
0157         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
0158             v->byte_per_pixel_in_dety[k] = 4.0;
0159             v->byte_per_pixel_in_detc[k] = 0.0;
0160         }
0161         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
0162             v->byte_per_pixel_in_dety[k] = 2.0;
0163             v->byte_per_pixel_in_detc[k] = 0.0;
0164         }
0165         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
0166             v->byte_per_pixel_in_dety[k] = 1.0;
0167             v->byte_per_pixel_in_detc[k] = 2.0;
0168         }
0169         else {
0170             v->byte_per_pixel_in_dety[k] = 4.0f / 3.0f;
0171             v->byte_per_pixel_in_detc[k] = 8.0f / 3.0f;
0172         }
0173     }
0174     v->total_read_bandwidth_consumed_gbyte_per_second = 0.0;
0175     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0176         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]);
0177         if (v->dcc_enable[k] == dcn_bw_yes) {
0178             v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256);
0179         }
0180         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)) {
0181             v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 64);
0182         }
0183         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)) {
0184             v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 256);
0185         }
0186         else if (v->pte_enable == dcn_bw_yes) {
0187             v->read_bandwidth[k] = v->read_bandwidth[k] * (1 + 1 / 512);
0188         }
0189         v->total_read_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->read_bandwidth[k] / 1000.0;
0190     }
0191     v->total_write_bandwidth_consumed_gbyte_per_second = 0.0;
0192     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0193         if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) {
0194             v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0;
0195         }
0196         else if (v->output[k] == dcn_bw_writeback) {
0197             v->write_bandwidth[k] = v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5;
0198         }
0199         else {
0200             v->write_bandwidth[k] = 0.0;
0201         }
0202         v->total_write_bandwidth_consumed_gbyte_per_second = v->total_write_bandwidth_consumed_gbyte_per_second + v->write_bandwidth[k] / 1000.0;
0203     }
0204     v->total_bandwidth_consumed_gbyte_per_second = v->total_read_bandwidth_consumed_gbyte_per_second + v->total_write_bandwidth_consumed_gbyte_per_second;
0205     v->dcc_enabled_in_any_plane = dcn_bw_no;
0206     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0207         if (v->dcc_enable[k] == dcn_bw_yes) {
0208             v->dcc_enabled_in_any_plane = dcn_bw_yes;
0209         }
0210     }
0211     for (i = 0; i <= number_of_states_plus_one; i++) {
0212         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);
0213         v->return_bw_per_state[i] = v->return_bw_todcn_per_state;
0214         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) {
0215             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)));
0216         }
0217         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);
0218         if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) {
0219             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));
0220         }
0221         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);
0222         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) {
0223             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)));
0224         }
0225         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);
0226         if (v->dcc_enabled_in_any_plane == dcn_bw_yes && v->critical_point > 1.0 && v->critical_point < 4.0) {
0227             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));
0228         }
0229     }
0230     for (i = 0; i <= number_of_states_plus_one; i++) {
0231         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)) {
0232             v->bandwidth_support[i] = dcn_bw_yes;
0233         }
0234         else {
0235             v->bandwidth_support[i] = dcn_bw_no;
0236         }
0237     }
0238     /*writeback latency support check*/
0239 
0240     v->writeback_latency_support = dcn_bw_yes;
0241     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0242         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) {
0243             v->writeback_latency_support = dcn_bw_no;
0244         }
0245         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) {
0246             v->writeback_latency_support = dcn_bw_no;
0247         }
0248     }
0249     /*re-ordering buffer support check*/
0250 
0251     for (i = 0; i <= number_of_states_plus_one; i++) {
0252         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];
0253         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]) {
0254             v->rob_support[i] = dcn_bw_yes;
0255         }
0256         else {
0257             v->rob_support[i] = dcn_bw_no;
0258         }
0259     }
0260     /*display io support check*/
0261 
0262     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0263         if (v->output[k] == dcn_bw_dp && v->dsc_capability == dcn_bw_yes) {
0264             if (v->output_format[k] == dcn_bw_420) {
0265                 v->required_output_bw = v->pixel_clock[k] / 2.0;
0266             }
0267             else {
0268                 v->required_output_bw = v->pixel_clock[k];
0269             }
0270         }
0271         else if (v->output_format[k] == dcn_bw_420) {
0272             v->required_output_bw = v->pixel_clock[k] * 3.0 / 2.0;
0273         }
0274         else {
0275             v->required_output_bw = v->pixel_clock[k] * 3.0;
0276         }
0277         if (v->output[k] == dcn_bw_hdmi) {
0278             v->required_phyclk[k] = v->required_output_bw;
0279             switch (v->output_deep_color[k]) {
0280             case dcn_bw_encoder_10bpc:
0281                 v->required_phyclk[k] =  v->required_phyclk[k] * 5.0 / 4;
0282             break;
0283             case dcn_bw_encoder_12bpc:
0284                 v->required_phyclk[k] =  v->required_phyclk[k] * 3.0 / 2;
0285                 break;
0286             default:
0287                 break;
0288             }
0289             v->required_phyclk[k] = v->required_phyclk[k] / 3.0;
0290         }
0291         else if (v->output[k] == dcn_bw_dp) {
0292             v->required_phyclk[k] = v->required_output_bw / 4.0;
0293         }
0294         else {
0295             v->required_phyclk[k] = 0.0;
0296         }
0297     }
0298     for (i = 0; i <= number_of_states_plus_one; i++) {
0299         v->dio_support[i] = dcn_bw_yes;
0300         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0301             if (v->required_phyclk[k] > v->phyclk_per_state[i] || (v->output[k] == dcn_bw_hdmi && v->required_phyclk[k] > 600.0)) {
0302                 v->dio_support[i] = dcn_bw_no;
0303             }
0304         }
0305     }
0306     /*total available writeback support check*/
0307 
0308     v->total_number_of_active_writeback = 0.0;
0309     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0310         if (v->output[k] == dcn_bw_writeback) {
0311             v->total_number_of_active_writeback = v->total_number_of_active_writeback + 1.0;
0312         }
0313     }
0314     if (v->total_number_of_active_writeback <= v->max_num_writeback) {
0315         v->total_available_writeback_support = dcn_bw_yes;
0316     }
0317     else {
0318         v->total_available_writeback_support = dcn_bw_no;
0319     }
0320     /*maximum dispclk/dppclk support check*/
0321 
0322     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0323         if (v->h_ratio[k] > 1.0) {
0324             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));
0325         }
0326         else {
0327             v->pscl_factor[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
0328         }
0329         if (v->byte_per_pixel_in_detc[k] == 0.0) {
0330             v->pscl_factor_chroma[k] = 0.0;
0331             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);
0332         }
0333         else {
0334             if (v->h_ratio[k] / 2.0 > 1.0) {
0335                 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));
0336             }
0337             else {
0338                 v->pscl_factor_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
0339             }
0340             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);
0341         }
0342     }
0343     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0344         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)) {
0345             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0346                 v->read256_block_height_y[k] = 1.0;
0347             }
0348             else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
0349                 v->read256_block_height_y[k] = 4.0;
0350             }
0351             else {
0352                 v->read256_block_height_y[k] = 8.0;
0353             }
0354             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];
0355             v->read256_block_height_c[k] = 0.0;
0356             v->read256_block_width_c[k] = 0.0;
0357         }
0358         else {
0359             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0360                 v->read256_block_height_y[k] = 1.0;
0361                 v->read256_block_height_c[k] = 1.0;
0362             }
0363             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
0364                 v->read256_block_height_y[k] = 16.0;
0365                 v->read256_block_height_c[k] = 8.0;
0366             }
0367             else {
0368                 v->read256_block_height_y[k] = 8.0;
0369                 v->read256_block_height_c[k] = 8.0;
0370             }
0371             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];
0372             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];
0373         }
0374         if (v->source_scan[k] == dcn_bw_hor) {
0375             v->max_swath_height_y[k] = v->read256_block_height_y[k];
0376             v->max_swath_height_c[k] = v->read256_block_height_c[k];
0377         }
0378         else {
0379             v->max_swath_height_y[k] = v->read256_block_width_y[k];
0380             v->max_swath_height_c[k] = v->read256_block_width_c[k];
0381         }
0382         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)) {
0383             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)) {
0384                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
0385             }
0386             else {
0387                 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
0388             }
0389             v->min_swath_height_c[k] = v->max_swath_height_c[k];
0390         }
0391         else {
0392             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0393                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
0394                 v->min_swath_height_c[k] = v->max_swath_height_c[k];
0395             }
0396             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) {
0397                 v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
0398                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
0399                     v->min_swath_height_c[k] = v->max_swath_height_c[k];
0400                 }
0401                 else {
0402                     v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0;
0403                 }
0404             }
0405             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) {
0406                 v->min_swath_height_c[k] = v->max_swath_height_c[k] / 2.0;
0407                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
0408                     v->min_swath_height_y[k] = v->max_swath_height_y[k];
0409                 }
0410                 else {
0411                     v->min_swath_height_y[k] = v->max_swath_height_y[k] / 2.0;
0412                 }
0413             }
0414             else {
0415                 v->min_swath_height_y[k] = v->max_swath_height_y[k];
0416                 v->min_swath_height_c[k] = v->max_swath_height_c[k];
0417             }
0418         }
0419         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0420             v->maximum_swath_width = 8192.0;
0421         }
0422         else {
0423             v->maximum_swath_width = 5120.0;
0424         }
0425         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);
0426         if (v->byte_per_pixel_in_detc[k] == 0.0) {
0427             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);
0428         }
0429         else {
0430             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));
0431         }
0432         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);
0433     }
0434     for (i = 0; i <= number_of_states_plus_one; i++) {
0435         for (j = 0; j <= 1; j++) {
0436             v->total_number_of_active_dpp[i][j] = 0.0;
0437             v->required_dispclk[i][j] = 0.0;
0438             v->dispclk_dppclk_support[i][j] = dcn_bw_yes;
0439             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0440                 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);
0441                 if (v->odm_capability == dcn_bw_yes) {
0442                     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);
0443                 }
0444                 else {
0445                     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);
0446                 }
0447                 if (i < number_of_states) {
0448                     v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
0449                     v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
0450                 }
0451                 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) {
0452                     v->no_of_dpp[i][j][k] = 1.0;
0453                     v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp);
0454                 }
0455                 else if (v->min_dispclk_using_dual_dpp <=dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
0456                     v->no_of_dpp[i][j][k] = 2.0;
0457                     v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
0458                 }
0459                 else {
0460                     v->no_of_dpp[i][j][k] = 2.0;
0461                     v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
0462                     v->dispclk_dppclk_support[i][j] = dcn_bw_no;
0463                 }
0464                 v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k];
0465             }
0466             if (v->total_number_of_active_dpp[i][j] > v->max_num_dpp) {
0467                 v->total_number_of_active_dpp[i][j] = 0.0;
0468                 v->required_dispclk[i][j] = 0.0;
0469                 v->dispclk_dppclk_support[i][j] = dcn_bw_yes;
0470                 for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0471                     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);
0472                     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);
0473                     if (i < number_of_states) {
0474                         v->min_dispclk_using_single_dpp = v->min_dispclk_using_single_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
0475                         v->min_dispclk_using_dual_dpp = v->min_dispclk_using_dual_dpp * (1.0 + v->dispclk_ramping_margin / 100.0);
0476                     }
0477                     if (v->number_of_dpp_required_for_det_and_lb_size[k] <= 1.0) {
0478                         v->no_of_dpp[i][j][k] = 1.0;
0479                         v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_single_dpp);
0480                         if (v->min_dispclk_using_single_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
0481                             v->dispclk_dppclk_support[i][j] = dcn_bw_no;
0482                         }
0483                     }
0484                     else {
0485                         v->no_of_dpp[i][j][k] = 2.0;
0486                         v->required_dispclk[i][j] =dcn_bw_max2(v->required_dispclk[i][j], v->min_dispclk_using_dual_dpp);
0487                         if (v->min_dispclk_using_dual_dpp >dcn_bw_min2(v->max_dispclk[i], (j + 1) * v->max_dppclk[i])) {
0488                             v->dispclk_dppclk_support[i][j] = dcn_bw_no;
0489                         }
0490                     }
0491                     v->total_number_of_active_dpp[i][j] = v->total_number_of_active_dpp[i][j] + v->no_of_dpp[i][j][k];
0492                 }
0493             }
0494         }
0495     }
0496     /*viewport size check*/
0497 
0498     v->viewport_size_support = dcn_bw_yes;
0499     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0500         if (v->number_of_dpp_required_for_det_and_lb_size[k] > 2.0) {
0501             v->viewport_size_support = dcn_bw_no;
0502         }
0503     }
0504     /*total available pipes support check*/
0505 
0506     for (i = 0; i <= number_of_states_plus_one; i++) {
0507         for (j = 0; j <= 1; j++) {
0508             if (v->total_number_of_active_dpp[i][j] <= v->max_num_dpp) {
0509                 v->total_available_pipes_support[i][j] = dcn_bw_yes;
0510             }
0511             else {
0512                 v->total_available_pipes_support[i][j] = dcn_bw_no;
0513             }
0514         }
0515     }
0516     /*urgent latency support check*/
0517 
0518     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0519         for (i = 0; i <= number_of_states_plus_one; i++) {
0520             for (j = 0; j <= 1; j++) {
0521                 v->swath_width_yper_state[i][j][k] = v->swath_width_ysingle_dpp[k] / v->no_of_dpp[i][j][k];
0522                 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];
0523                 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];
0524                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
0525                     v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256;
0526                 }
0527                 if (v->max_swath_height_c[k] > 0.0) {
0528                     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];
0529                 }
0530                 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];
0531                 if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
0532                     v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256;
0533                 }
0534                 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) {
0535                     v->swath_height_yper_state[i][j][k] = v->max_swath_height_y[k];
0536                     v->swath_height_cper_state[i][j][k] = v->max_swath_height_c[k];
0537                 }
0538                 else {
0539                     v->swath_height_yper_state[i][j][k] = v->min_swath_height_y[k];
0540                     v->swath_height_cper_state[i][j][k] = v->min_swath_height_c[k];
0541                 }
0542                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
0543                     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];
0544                     v->lines_in_det_chroma = 0.0;
0545                 }
0546                 else if (v->swath_height_yper_state[i][j][k] <= v->swath_height_cper_state[i][j][k]) {
0547                     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];
0548                     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);
0549                 }
0550                 else {
0551                     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];
0552                     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);
0553                 }
0554                 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);
0555                 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);
0556                 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]);
0557                 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]);
0558                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
0559                     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]);
0560                 }
0561                 else {
0562                     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]));
0563                 }
0564             }
0565         }
0566     }
0567     for (i = 0; i <= number_of_states_plus_one; i++) {
0568         for (j = 0; j <= 1; j++) {
0569             v->urgent_latency_support[i][j] = dcn_bw_yes;
0570             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0571                 if (v->urgent_latency_support_us_per_state[i][j][k] < v->urgent_latency / 1.0) {
0572                     v->urgent_latency_support[i][j] = dcn_bw_no;
0573                 }
0574             }
0575         }
0576     }
0577     /*prefetch check*/
0578 
0579     for (i = 0; i <= number_of_states_plus_one; i++) {
0580         for (j = 0; j <= 1; j++) {
0581             v->total_number_of_dcc_active_dpp[i][j] = 0.0;
0582             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0583                 if (v->dcc_enable[k] == dcn_bw_yes) {
0584                     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];
0585                 }
0586             }
0587         }
0588     }
0589     for (i = 0; i <= number_of_states_plus_one; i++) {
0590         for (j = 0; j <= 1; j++) {
0591             v->projected_dcfclk_deep_sleep = 8.0;
0592             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0593                 v->projected_dcfclk_deep_sleep =dcn_bw_max2(v->projected_dcfclk_deep_sleep, v->pixel_clock[k] / 16.0);
0594                 if (v->byte_per_pixel_in_detc[k] == 0.0) {
0595                     if (v->v_ratio[k] <= 1.0) {
0596                         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]);
0597                     }
0598                     else {
0599                         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));
0600                     }
0601                 }
0602                 else {
0603                     if (v->v_ratio[k] <= 1.0) {
0604                         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]);
0605                     }
0606                     else {
0607                         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));
0608                     }
0609                     if (v->v_ratio[k] / 2.0 <= 1.0) {
0610                         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]);
0611                     }
0612                     else {
0613                         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));
0614                     }
0615                 }
0616             }
0617             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0618                 if (v->dcc_enable[k] == dcn_bw_yes) {
0619                     v->meta_req_height_y = 8.0 * v->read256_block_height_y[k];
0620                     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;
0621                     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;
0622                     v->meta_surface_height_y =dcn_bw_ceil2(v->viewport_height[k] - 1.0, v->meta_req_height_y) + v->meta_req_height_y;
0623                     if (v->pte_enable == dcn_bw_yes) {
0624                         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;
0625                     }
0626                     else {
0627                         v->meta_pte_bytes_per_frame_y = 0.0;
0628                     }
0629                     if (v->source_scan[k] == dcn_bw_hor) {
0630                         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;
0631                     }
0632                     else {
0633                         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;
0634                     }
0635                 }
0636                 else {
0637                     v->meta_pte_bytes_per_frame_y = 0.0;
0638                     v->meta_row_bytes_y = 0.0;
0639                 }
0640                 if (v->pte_enable == dcn_bw_yes) {
0641                     if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0642                         v->macro_tile_block_size_bytes_y = 256.0;
0643                         v->macro_tile_block_height_y = 1.0;
0644                     }
0645                     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) {
0646                         v->macro_tile_block_size_bytes_y = 4096.0;
0647                         v->macro_tile_block_height_y = 4.0 * v->read256_block_height_y[k];
0648                     }
0649                     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) {
0650                         v->macro_tile_block_size_bytes_y = 64.0 * 1024;
0651                         v->macro_tile_block_height_y = 16.0 * v->read256_block_height_y[k];
0652                     }
0653                     else {
0654                         v->macro_tile_block_size_bytes_y = 256.0 * 1024;
0655                         v->macro_tile_block_height_y = 32.0 * v->read256_block_height_y[k];
0656                     }
0657                     if (v->macro_tile_block_size_bytes_y <= 65536.0) {
0658                         v->data_pte_req_height_y = v->macro_tile_block_height_y;
0659                     }
0660                     else {
0661                         v->data_pte_req_height_y = 16.0 * v->read256_block_height_y[k];
0662                     }
0663                     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;
0664                     if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0665                         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);
0666                     }
0667                     else if (v->source_scan[k] == dcn_bw_hor) {
0668                         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);
0669                     }
0670                     else {
0671                         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);
0672                     }
0673                 }
0674                 else {
0675                     v->dpte_bytes_per_row_y = 0.0;
0676                 }
0677                 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)) {
0678                     if (v->dcc_enable[k] == dcn_bw_yes) {
0679                         v->meta_req_height_c = 8.0 * v->read256_block_height_c[k];
0680                         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;
0681                         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;
0682                         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;
0683                         if (v->pte_enable == dcn_bw_yes) {
0684                             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;
0685                         }
0686                         else {
0687                             v->meta_pte_bytes_per_frame_c = 0.0;
0688                         }
0689                         if (v->source_scan[k] == dcn_bw_hor) {
0690                             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;
0691                         }
0692                         else {
0693                             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;
0694                         }
0695                     }
0696                     else {
0697                         v->meta_pte_bytes_per_frame_c = 0.0;
0698                         v->meta_row_bytes_c = 0.0;
0699                     }
0700                     if (v->pte_enable == dcn_bw_yes) {
0701                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0702                             v->macro_tile_block_size_bytes_c = 256.0;
0703                             v->macro_tile_block_height_c = 1.0;
0704                         }
0705                         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) {
0706                             v->macro_tile_block_size_bytes_c = 4096.0;
0707                             v->macro_tile_block_height_c = 4.0 * v->read256_block_height_c[k];
0708                         }
0709                         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) {
0710                             v->macro_tile_block_size_bytes_c = 64.0 * 1024;
0711                             v->macro_tile_block_height_c = 16.0 * v->read256_block_height_c[k];
0712                         }
0713                         else {
0714                             v->macro_tile_block_size_bytes_c = 256.0 * 1024;
0715                             v->macro_tile_block_height_c = 32.0 * v->read256_block_height_c[k];
0716                         }
0717                         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;
0718                         if (v->macro_tile_block_size_bytes_c <= 65536.0) {
0719                             v->data_pte_req_height_c = v->macro_tile_block_height_c;
0720                         }
0721                         else {
0722                             v->data_pte_req_height_c = 16.0 * v->read256_block_height_c[k];
0723                         }
0724                         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;
0725                         if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
0726                             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);
0727                         }
0728                         else if (v->source_scan[k] == dcn_bw_hor) {
0729                             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);
0730                         }
0731                         else {
0732                             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);
0733                         }
0734                     }
0735                     else {
0736                         v->dpte_bytes_per_row_c = 0.0;
0737                     }
0738                 }
0739                 else {
0740                     v->dpte_bytes_per_row_c = 0.0;
0741                     v->meta_pte_bytes_per_frame_c = 0.0;
0742                     v->meta_row_bytes_c = 0.0;
0743                 }
0744                 v->dpte_bytes_per_row[k] = v->dpte_bytes_per_row_y + v->dpte_bytes_per_row_c;
0745                 v->meta_pte_bytes_per_frame[k] = v->meta_pte_bytes_per_frame_y + v->meta_pte_bytes_per_frame_c;
0746                 v->meta_row_bytes[k] = v->meta_row_bytes_y + v->meta_row_bytes_c;
0747                 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;
0748                 v->prefill_y[k] =dcn_bw_floor2(v->v_init_y, 1.0);
0749                 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;
0750                 if (v->prefill_y[k] > 1.0) {
0751                     v->max_partial_sw_y =dcn_bw_mod((v->prefill_y[k] - 2.0), v->swath_height_yper_state[i][j][k]);
0752                 }
0753                 else {
0754                     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]);
0755                 }
0756                 v->max_partial_sw_y =dcn_bw_max2(1.0, v->max_partial_sw_y);
0757                 v->prefetch_lines_y[k] = v->max_num_sw_y[k] * v->swath_height_yper_state[i][j][k] + v->max_partial_sw_y;
0758                 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)) {
0759                     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;
0760                     v->prefill_c[k] =dcn_bw_floor2(v->v_init_c, 1.0);
0761                     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;
0762                     if (v->prefill_c[k] > 1.0) {
0763                         v->max_partial_sw_c =dcn_bw_mod((v->prefill_c[k] - 2.0), v->swath_height_cper_state[i][j][k]);
0764                     }
0765                     else {
0766                         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]);
0767                     }
0768                     v->max_partial_sw_c =dcn_bw_max2(1.0, v->max_partial_sw_c);
0769                     v->prefetch_lines_c[k] = v->max_num_sw_c[k] * v->swath_height_cper_state[i][j][k] + v->max_partial_sw_c;
0770                 }
0771                 else {
0772                     v->prefetch_lines_c[k] = 0.0;
0773                 }
0774                 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];
0775                 if (v->no_of_dpp[i][j][k] > 1.0) {
0776                     v->dst_x_after_scaler = v->dst_x_after_scaler + v->scaler_rec_out_width[k] / 2.0;
0777                 }
0778                 if (v->output_format[k] == dcn_bw_420) {
0779                     v->dst_y_after_scaler = 1.0;
0780                 }
0781                 else {
0782                     v->dst_y_after_scaler = 0.0;
0783                 }
0784                 v->time_calc = 24.0 / v->projected_dcfclk_deep_sleep;
0785                 v->v_update_offset[k][j] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0);
0786                 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]);
0787                 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];
0788                 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];
0789                 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];
0790                 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];
0791                 if (v->pte_enable == dcn_bw_yes) {
0792                     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];
0793                 }
0794                 if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) {
0795                     v->maximum_vstartup = v->vtotal[k] - v->vactive[k] - 1.0;
0796                 }
0797                 else {
0798                     v->maximum_vstartup = v->v_sync_plus_back_porch[k] - 1.0;
0799                 }
0800 
0801                 do {
0802                     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]);
0803                     v->line_times_for_prefetch[k] =dcn_bw_floor2(4.0 * (v->line_times_for_prefetch[k] + 0.125), 1.0) / 4;
0804                     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]);
0805 
0806                     if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
0807                         v->time_for_meta_pte_without_immediate_flip = dcn_bw_max3(
0808                                 v->meta_pte_bytes_frame[k] / v->prefetch_bw[k],
0809                                 v->extra_latency,
0810                                 v->htotal[k] / v->pixel_clock[k] / 4.0);
0811                     } else {
0812                         v->time_for_meta_pte_without_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0;
0813                     }
0814 
0815                     if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) {
0816                         v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max3((
0817                                 v->meta_row_bytes[k] + v->dpte_bytes_per_row[k]) / v->prefetch_bw[k],
0818                                 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip,
0819                                 v->extra_latency);
0820                     } else {
0821                         v->time_for_meta_and_dpte_row_without_immediate_flip = dcn_bw_max2(
0822                                 v->htotal[k] / v->pixel_clock[k] - v->time_for_meta_pte_without_immediate_flip,
0823                                 v->extra_latency - v->time_for_meta_pte_with_immediate_flip);
0824                     }
0825 
0826                     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;
0827                     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;
0828                     v->maximum_vstartup = v->maximum_vstartup - 1;
0829 
0830                     if (v->lines_for_meta_pte_without_immediate_flip[k] < 32.0 && v->lines_for_meta_and_dpte_row_without_immediate_flip[k] < 16.0)
0831                         break;
0832 
0833                 } while(1);
0834             }
0835             v->bw_available_for_immediate_flip = v->return_bw_per_state[i];
0836             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0837                 v->bw_available_for_immediate_flip = v->bw_available_for_immediate_flip -dcn_bw_max2(v->read_bandwidth[k], v->prefetch_bw[k]);
0838             }
0839             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0840                 v->total_immediate_flip_bytes[k] = 0.0;
0841                 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
0842                     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];
0843                 }
0844             }
0845             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0846                 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
0847                     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);
0848                 }
0849                 else {
0850                     v->time_for_meta_pte_with_immediate_flip = v->htotal[k] / v->pixel_clock[k] / 4.0;
0851                 }
0852                 if (v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes) {
0853                     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);
0854                 }
0855                 else {
0856                     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);
0857                 }
0858                 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;
0859                 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;
0860                 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];
0861                 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];
0862                 if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip > 0.0) {
0863                     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;
0864                     if ((v->swath_height_yper_state[i][j][k] > 4.0)) {
0865                         if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) {
0866                             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));
0867                         }
0868                         else {
0869                             v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0;
0870                         }
0871                     }
0872                     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;
0873                     if ((v->swath_height_cper_state[i][j][k] > 4.0)) {
0874                         if (v->line_times_to_request_prefetch_pixel_data_with_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) {
0875                             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));
0876                         }
0877                         else {
0878                             v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0;
0879                         }
0880                     }
0881                     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]);
0882                 }
0883                 else {
0884                     v->v_ratio_pre_ywith_immediate_flip[i][j][k] = 999999.0;
0885                     v->v_ratio_pre_cwith_immediate_flip[i][j][k] = 999999.0;
0886                     v->required_prefetch_pixel_data_bw_with_immediate_flip[i][j][k] = 999999.0;
0887                 }
0888                 if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip > 0.0) {
0889                     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;
0890                     if ((v->swath_height_yper_state[i][j][k] > 4.0)) {
0891                         if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_y[k] - 3.0) / 2.0 > 0.0) {
0892                             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));
0893                         }
0894                         else {
0895                             v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0;
0896                         }
0897                     }
0898                     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;
0899                     if ((v->swath_height_cper_state[i][j][k] > 4.0)) {
0900                         if (v->line_times_to_request_prefetch_pixel_data_without_immediate_flip - (v->prefill_c[k] - 3.0) / 2.0 > 0.0) {
0901                             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));
0902                         }
0903                         else {
0904                             v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0;
0905                         }
0906                     }
0907                     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]);
0908                 }
0909                 else {
0910                     v->v_ratio_pre_ywithout_immediate_flip[i][j][k] = 999999.0;
0911                     v->v_ratio_pre_cwithout_immediate_flip[i][j][k] = 999999.0;
0912                     v->required_prefetch_pixel_data_bw_without_immediate_flip[i][j][k] = 999999.0;
0913                 }
0914             }
0915             v->maximum_read_bandwidth_with_prefetch_with_immediate_flip = 0.0;
0916             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0917                 if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
0918                     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]));
0919                 }
0920                 else {
0921                     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]);
0922                 }
0923             }
0924             v->maximum_read_bandwidth_with_prefetch_without_immediate_flip = 0.0;
0925             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0926                 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]);
0927             }
0928             v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes;
0929             if (v->maximum_read_bandwidth_with_prefetch_with_immediate_flip > v->return_bw_per_state[i]) {
0930                 v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
0931             }
0932             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0933                 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) {
0934                     v->prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
0935                 }
0936             }
0937             v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes;
0938             if (v->maximum_read_bandwidth_with_prefetch_without_immediate_flip > v->return_bw_per_state[i]) {
0939                 v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
0940             }
0941             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0942                 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) {
0943                     v->prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
0944                 }
0945             }
0946         }
0947     }
0948     for (i = 0; i <= number_of_states_plus_one; i++) {
0949         for (j = 0; j <= 1; j++) {
0950             v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_yes;
0951             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0952                 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)))) {
0953                     v->v_ratio_in_prefetch_supported_with_immediate_flip[i][j] = dcn_bw_no;
0954                 }
0955             }
0956             v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_yes;
0957             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
0958                 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)) {
0959                     v->v_ratio_in_prefetch_supported_without_immediate_flip[i][j] = dcn_bw_no;
0960                 }
0961             }
0962         }
0963     }
0964     /*mode support, voltage state and soc configuration*/
0965 
0966     for (i = number_of_states_plus_one; i >= 0; i--) {
0967         for (j = 0; j <= 1; j++) {
0968             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) {
0969                 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) {
0970                     v->mode_support_with_immediate_flip[i][j] = dcn_bw_yes;
0971                 }
0972                 else {
0973                     v->mode_support_with_immediate_flip[i][j] = dcn_bw_no;
0974                 }
0975                 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) {
0976                     v->mode_support_without_immediate_flip[i][j] = dcn_bw_yes;
0977                 }
0978                 else {
0979                     v->mode_support_without_immediate_flip[i][j] = dcn_bw_no;
0980                 }
0981             }
0982             else {
0983                 v->mode_support_with_immediate_flip[i][j] = dcn_bw_no;
0984                 v->mode_support_without_immediate_flip[i][j] = dcn_bw_no;
0985             }
0986         }
0987     }
0988     for (i = number_of_states_plus_one; i >= 0; i--) {
0989         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) {
0990             v->voltage_level_with_immediate_flip = i;
0991         }
0992     }
0993     for (i = number_of_states_plus_one; i >= 0; i--) {
0994         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) {
0995             v->voltage_level_without_immediate_flip = i;
0996         }
0997     }
0998     if (v->voltage_level_with_immediate_flip == number_of_states_plus_one) {
0999         v->immediate_flip_supported = dcn_bw_no;
1000         v->voltage_level = v->voltage_level_without_immediate_flip;
1001     }
1002     else {
1003         v->immediate_flip_supported = dcn_bw_yes;
1004         v->voltage_level = v->voltage_level_with_immediate_flip;
1005     }
1006     v->dcfclk = v->dcfclk_per_state[v->voltage_level];
1007     v->fabric_and_dram_bandwidth = v->fabric_and_dram_bandwidth_per_state[v->voltage_level];
1008     for (j = 0; j <= 1; j++) {
1009         v->required_dispclk_per_ratio[j] = v->required_dispclk[v->voltage_level][j];
1010         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1011             v->dpp_per_plane_per_ratio[j][k] = v->no_of_dpp[v->voltage_level][j][k];
1012         }
1013         v->dispclk_dppclk_support_per_ratio[j] = v->dispclk_dppclk_support[v->voltage_level][j];
1014     }
1015     v->max_phyclk = v->phyclk_per_state[v->voltage_level];
1016 }
1017 void display_pipe_configuration(struct dcn_bw_internal_vars *v)
1018 {
1019     int j;
1020     int k;
1021     /*display pipe configuration*/
1022 
1023     for (j = 0; j <= 1; j++) {
1024         v->total_number_of_active_dpp_per_ratio[j] = 0.0;
1025         for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1026             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];
1027         }
1028     }
1029     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]))))) {
1030         v->dispclk_dppclk_ratio = 1;
1031         v->final_error_message = v->error_message[0];
1032     }
1033     else {
1034         v->dispclk_dppclk_ratio = 2;
1035         v->final_error_message = v->error_message[1];
1036     }
1037     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1038         v->dpp_per_plane[k] = v->dpp_per_plane_per_ratio[v->dispclk_dppclk_ratio - 1][k];
1039     }
1040     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1041         if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
1042             v->byte_per_pix_dety = 8.0;
1043             v->byte_per_pix_detc = 0.0;
1044         }
1045         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
1046             v->byte_per_pix_dety = 4.0;
1047             v->byte_per_pix_detc = 0.0;
1048         }
1049         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
1050             v->byte_per_pix_dety = 2.0;
1051             v->byte_per_pix_detc = 0.0;
1052         }
1053         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
1054             v->byte_per_pix_dety = 1.0;
1055             v->byte_per_pix_detc = 2.0;
1056         }
1057         else {
1058             v->byte_per_pix_dety = 4.0f / 3.0f;
1059             v->byte_per_pix_detc = 8.0f / 3.0f;
1060         }
1061         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)) {
1062             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1063                 v->read256_bytes_block_height_y = 1.0;
1064             }
1065             else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
1066                 v->read256_bytes_block_height_y = 4.0;
1067             }
1068             else {
1069                 v->read256_bytes_block_height_y = 8.0;
1070             }
1071             v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y;
1072             v->read256_bytes_block_height_c = 0.0;
1073             v->read256_bytes_block_width_c = 0.0;
1074         }
1075         else {
1076             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1077                 v->read256_bytes_block_height_y = 1.0;
1078                 v->read256_bytes_block_height_c = 1.0;
1079             }
1080             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
1081                 v->read256_bytes_block_height_y = 16.0;
1082                 v->read256_bytes_block_height_c = 8.0;
1083             }
1084             else {
1085                 v->read256_bytes_block_height_y = 8.0;
1086                 v->read256_bytes_block_height_c = 8.0;
1087             }
1088             v->read256_bytes_block_width_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->read256_bytes_block_height_y;
1089             v->read256_bytes_block_width_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->read256_bytes_block_height_c;
1090         }
1091         if (v->source_scan[k] == dcn_bw_hor) {
1092             v->maximum_swath_height_y = v->read256_bytes_block_height_y;
1093             v->maximum_swath_height_c = v->read256_bytes_block_height_c;
1094         }
1095         else {
1096             v->maximum_swath_height_y = v->read256_bytes_block_width_y;
1097             v->maximum_swath_height_c = v->read256_bytes_block_width_c;
1098         }
1099         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)) {
1100             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)) {
1101                 v->minimum_swath_height_y = v->maximum_swath_height_y;
1102             }
1103             else {
1104                 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
1105             }
1106             v->minimum_swath_height_c = v->maximum_swath_height_c;
1107         }
1108         else {
1109             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1110                 v->minimum_swath_height_y = v->maximum_swath_height_y;
1111                 v->minimum_swath_height_c = v->maximum_swath_height_c;
1112             }
1113             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8 && v->source_scan[k] == dcn_bw_hor) {
1114                 v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
1115                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
1116                     v->minimum_swath_height_c = v->maximum_swath_height_c;
1117                 }
1118                 else {
1119                     v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0;
1120                 }
1121             }
1122             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10 && v->source_scan[k] == dcn_bw_hor) {
1123                 v->minimum_swath_height_c = v->maximum_swath_height_c / 2.0;
1124                 if (v->bug_forcing_luma_and_chroma_request_to_same_size_fixed == dcn_bw_yes) {
1125                     v->minimum_swath_height_y = v->maximum_swath_height_y;
1126                 }
1127                 else {
1128                     v->minimum_swath_height_y = v->maximum_swath_height_y / 2.0;
1129                 }
1130             }
1131             else {
1132                 v->minimum_swath_height_y = v->maximum_swath_height_y;
1133                 v->minimum_swath_height_c = v->maximum_swath_height_c;
1134             }
1135         }
1136         if (v->source_scan[k] == dcn_bw_hor) {
1137             v->swath_width = v->viewport_width[k] / v->dpp_per_plane[k];
1138         }
1139         else {
1140             v->swath_width = v->viewport_height[k] / v->dpp_per_plane[k];
1141         }
1142         v->swath_width_granularity_y = 256.0 /dcn_bw_ceil2(v->byte_per_pix_dety, 1.0) / v->maximum_swath_height_y;
1143         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;
1144         if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
1145             v->rounded_up_max_swath_size_bytes_y =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_y, 256.0) + 256;
1146         }
1147         if (v->maximum_swath_height_c > 0.0) {
1148             v->swath_width_granularity_c = 256.0 /dcn_bw_ceil2(v->byte_per_pix_detc, 2.0) / v->maximum_swath_height_c;
1149         }
1150         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;
1151         if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_10) {
1152             v->rounded_up_max_swath_size_bytes_c =dcn_bw_ceil2(v->rounded_up_max_swath_size_bytes_c, 256.0) + 256;
1153         }
1154         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) {
1155             v->swath_height_y[k] = v->maximum_swath_height_y;
1156             v->swath_height_c[k] = v->maximum_swath_height_c;
1157         }
1158         else {
1159             v->swath_height_y[k] = v->minimum_swath_height_y;
1160             v->swath_height_c[k] = v->minimum_swath_height_c;
1161         }
1162         if (v->swath_height_c[k] == 0.0) {
1163             v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0;
1164             v->det_buffer_size_c[k] = 0.0;
1165         }
1166         else if (v->swath_height_y[k] <= v->swath_height_c[k]) {
1167             v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0;
1168             v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 2.0;
1169         }
1170         else {
1171             v->det_buffer_size_y[k] = v->det_buffer_size_in_kbyte * 1024.0 * 2.0 / 3.0;
1172             v->det_buffer_size_c[k] = v->det_buffer_size_in_kbyte * 1024.0 / 3.0;
1173         }
1174     }
1175 }
1176 void dispclkdppclkdcfclk_deep_sleep_prefetch_parameters_watermarks_and_performance_calculation(struct dcn_bw_internal_vars *v)
1177 {
1178     int k;
1179     /*dispclk and dppclk calculation*/
1180 
1181     v->dispclk_with_ramping = 0.0;
1182     v->dispclk_without_ramping = 0.0;
1183     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1184         if (v->h_ratio[k] > 1.0) {
1185             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));
1186         }
1187         else {
1188             v->pscl_throughput[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
1189         }
1190         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);
1191         if ((v->source_pixel_format[k] != dcn_bw_yuv420_sub_8 && v->source_pixel_format[k] != dcn_bw_yuv420_sub_10)) {
1192             v->pscl_throughput_chroma[k] = 0.0;
1193             v->dppclk_using_single_dpp = v->dppclk_using_single_dpp_luma;
1194         }
1195         else {
1196             if (v->h_ratio[k] > 1.0) {
1197                 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));
1198             }
1199             else {
1200                 v->pscl_throughput_chroma[k] =dcn_bw_min2(v->max_dchub_topscl_throughput, v->max_pscl_tolb_throughput);
1201             }
1202             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);
1203             v->dppclk_using_single_dpp =dcn_bw_max2(v->dppclk_using_single_dpp_luma, v->dppclk_using_single_dpp_chroma);
1204         }
1205         if (v->odm_capable == dcn_bw_yes) {
1206             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));
1207             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));
1208         }
1209         else {
1210             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));
1211             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));
1212         }
1213     }
1214     if (v->dispclk_without_ramping > v->max_dispclk[number_of_states]) {
1215         v->dispclk = v->dispclk_without_ramping;
1216     }
1217     else if (v->dispclk_with_ramping > v->max_dispclk[number_of_states]) {
1218         v->dispclk = v->max_dispclk[number_of_states];
1219     }
1220     else {
1221         v->dispclk = v->dispclk_with_ramping;
1222     }
1223     v->dppclk = v->dispclk / v->dispclk_dppclk_ratio;
1224     /*urgent watermark*/
1225 
1226     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);
1227     v->dcc_enabled_any_plane = dcn_bw_no;
1228     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1229         if (v->dcc_enable[k] == dcn_bw_yes) {
1230             v->dcc_enabled_any_plane = dcn_bw_yes;
1231         }
1232     }
1233     v->return_bw = v->return_bandwidth_to_dcn;
1234     if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) {
1235         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)));
1236     }
1237     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);
1238     if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) {
1239         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));
1240     }
1241     v->return_bandwidth_to_dcn =dcn_bw_min2(v->return_bus_width * v->dcfclk, v->fabric_and_dram_bandwidth * 1000.0);
1242     if (v->dcc_enabled_any_plane == dcn_bw_yes && v->return_bandwidth_to_dcn > v->dcfclk * v->return_bus_width / 4.0) {
1243         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)));
1244     }
1245     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);
1246     if (v->dcc_enabled_any_plane == dcn_bw_yes && v->critical_compression > 1.0 && v->critical_compression < 4.0) {
1247         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));
1248     }
1249     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1250         if (v->source_scan[k] == dcn_bw_hor) {
1251             v->swath_width_y[k] = v->viewport_width[k] / v->dpp_per_plane[k];
1252         }
1253         else {
1254             v->swath_width_y[k] = v->viewport_height[k] / v->dpp_per_plane[k];
1255         }
1256     }
1257     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1258         if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
1259             v->byte_per_pixel_dety[k] = 8.0;
1260             v->byte_per_pixel_detc[k] = 0.0;
1261         }
1262         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_32) {
1263             v->byte_per_pixel_dety[k] = 4.0;
1264             v->byte_per_pixel_detc[k] = 0.0;
1265         }
1266         else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_16) {
1267             v->byte_per_pixel_dety[k] = 2.0;
1268             v->byte_per_pixel_detc[k] = 0.0;
1269         }
1270         else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
1271             v->byte_per_pixel_dety[k] = 1.0;
1272             v->byte_per_pixel_detc[k] = 2.0;
1273         }
1274         else {
1275             v->byte_per_pixel_dety[k] = 4.0f / 3.0f;
1276             v->byte_per_pixel_detc[k] = 8.0f / 3.0f;
1277         }
1278     }
1279     v->total_data_read_bandwidth = 0.0;
1280     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1281         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];
1282         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;
1283         v->total_data_read_bandwidth = v->total_data_read_bandwidth + v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k];
1284     }
1285     v->total_active_dpp = 0.0;
1286     v->total_dcc_active_dpp = 0.0;
1287     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1288         v->total_active_dpp = v->total_active_dpp + v->dpp_per_plane[k];
1289         if (v->dcc_enable[k] == dcn_bw_yes) {
1290             v->total_dcc_active_dpp = v->total_dcc_active_dpp + v->dpp_per_plane[k];
1291         }
1292     }
1293     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;
1294     v->last_pixel_of_line_extra_watermark = 0.0;
1295     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1296         if (v->v_ratio[k] <= 1.0) {
1297             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];
1298         }
1299         else {
1300             v->display_pipe_line_delivery_time_luma[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
1301         }
1302         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);
1303         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]);
1304         if (v->byte_per_pixel_detc[k] == 0.0) {
1305             v->display_pipe_line_delivery_time_chroma[k] = 0.0;
1306         }
1307         else {
1308             if (v->v_ratio[k] / 2.0 <= 1.0) {
1309                 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];
1310             }
1311             else {
1312                 v->display_pipe_line_delivery_time_chroma[k] = v->swath_width_y[k] / 2.0 / v->pscl_throughput_chroma[k] / v->dppclk;
1313             }
1314             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);
1315             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]);
1316         }
1317     }
1318     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;
1319     if (v->pte_enable == dcn_bw_yes) {
1320         v->urgent_extra_latency = v->urgent_extra_latency + v->total_active_dpp * v->pte_chunk_size * 1024.0 / v->return_bw;
1321     }
1322     v->urgent_watermark = v->urgent_latency + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency;
1323     v->ptemeta_urgent_watermark = v->urgent_watermark + 2.0 * v->urgent_latency;
1324     /*nb p-state/dram clock change watermark*/
1325 
1326     v->dram_clock_change_watermark = v->dram_clock_change_latency + v->urgent_watermark;
1327     v->total_active_writeback = 0.0;
1328     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1329         if (v->output[k] == dcn_bw_writeback) {
1330             v->total_active_writeback = v->total_active_writeback + 1.0;
1331         }
1332     }
1333     if (v->total_active_writeback <= 1.0) {
1334         v->writeback_dram_clock_change_watermark = v->dram_clock_change_latency + v->write_back_latency;
1335     }
1336     else {
1337         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;
1338     }
1339     /*stutter efficiency*/
1340 
1341     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1342         v->lines_in_dety[k] = v->det_buffer_size_y[k] / v->byte_per_pixel_dety[k] / v->swath_width_y[k];
1343         v->lines_in_dety_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_dety[k], v->swath_height_y[k]);
1344         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];
1345         if (v->byte_per_pixel_detc[k] > 0.0) {
1346             v->lines_in_detc[k] = v->det_buffer_size_c[k] / v->byte_per_pixel_detc[k] / (v->swath_width_y[k] / 2.0);
1347             v->lines_in_detc_rounded_down_to_swath[k] =dcn_bw_floor2(v->lines_in_detc[k], v->swath_height_c[k]);
1348             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);
1349         }
1350         else {
1351             v->lines_in_detc[k] = 0.0;
1352             v->lines_in_detc_rounded_down_to_swath[k] = 0.0;
1353             v->full_det_buffering_time_c[k] = 999999.0;
1354         }
1355     }
1356     v->min_full_det_buffering_time = 999999.0;
1357     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1358         if (v->full_det_buffering_time_y[k] < v->min_full_det_buffering_time) {
1359             v->min_full_det_buffering_time = v->full_det_buffering_time_y[k];
1360             v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k];
1361         }
1362         if (v->full_det_buffering_time_c[k] < v->min_full_det_buffering_time) {
1363             v->min_full_det_buffering_time = v->full_det_buffering_time_c[k];
1364             v->frame_time_for_min_full_det_buffering_time = v->vtotal[k] * v->htotal[k] / v->pixel_clock[k];
1365         }
1366     }
1367     v->average_read_bandwidth_gbyte_per_second = 0.0;
1368     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1369         if (v->dcc_enable[k] == dcn_bw_yes) {
1370             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;
1371         }
1372         else {
1373             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;
1374         }
1375         if (v->dcc_enable[k] == dcn_bw_yes) {
1376             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;
1377         }
1378         if (v->pte_enable == dcn_bw_yes) {
1379             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;
1380         }
1381     }
1382     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));
1383     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);
1384     if (v->total_active_writeback == 0.0) {
1385         v->stutter_efficiency_not_including_vblank = (1.0 - (v->sr_exit_time + v->stutter_burst_time) / v->min_full_det_buffering_time) * 100.0;
1386     }
1387     else {
1388         v->stutter_efficiency_not_including_vblank = 0.0;
1389     }
1390     v->smallest_vblank = 999999.0;
1391     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1392         if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) {
1393             v->v_blank_time = (v->vtotal[k] - v->vactive[k]) * v->htotal[k] / v->pixel_clock[k];
1394         }
1395         else {
1396             v->v_blank_time = 0.0;
1397         }
1398         v->smallest_vblank =dcn_bw_min2(v->smallest_vblank, v->v_blank_time);
1399     }
1400     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;
1401     /*dcfclk deep sleep*/
1402 
1403     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1404         if (v->byte_per_pixel_detc[k] > 0.0) {
1405             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]);
1406         }
1407         else {
1408             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];
1409         }
1410         v->dcfclk_deep_sleep_per_plane[k] =dcn_bw_max2(v->dcfclk_deep_sleep_per_plane[k], v->pixel_clock[k] / 16.0);
1411     }
1412     v->dcf_clk_deep_sleep = 8.0;
1413     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1414         v->dcf_clk_deep_sleep =dcn_bw_max2(v->dcf_clk_deep_sleep, v->dcfclk_deep_sleep_per_plane[k]);
1415     }
1416     /*stutter watermark*/
1417 
1418     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;
1419     v->stutter_enter_plus_exit_watermark = v->sr_enter_plus_exit_time + v->last_pixel_of_line_extra_watermark + v->urgent_extra_latency;
1420     /*urgent latency supported*/
1421 
1422     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1423         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]);
1424         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]);
1425         if (v->byte_per_pixel_detc[k] > 0.0) {
1426             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]);
1427             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]);
1428             v->urgent_latency_support_us[k] =dcn_bw_min2(v->urgent_latency_support_us_luma, v->urgent_latency_support_us_chroma);
1429         }
1430         else {
1431             v->urgent_latency_support_us[k] = v->urgent_latency_support_us_luma;
1432         }
1433     }
1434     v->min_urgent_latency_support_us = 999999.0;
1435     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1436         v->min_urgent_latency_support_us =dcn_bw_min2(v->min_urgent_latency_support_us, v->urgent_latency_support_us[k]);
1437     }
1438     /*non-urgent latency tolerance*/
1439 
1440     v->non_urgent_latency_tolerance = v->min_urgent_latency_support_us - v->urgent_watermark;
1441     /*prefetch*/
1442 
1443     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1444         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)) {
1445             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1446                 v->block_height256_bytes_y = 1.0;
1447             }
1448             else if (v->source_pixel_format[k] == dcn_bw_rgb_sub_64) {
1449                 v->block_height256_bytes_y = 4.0;
1450             }
1451             else {
1452                 v->block_height256_bytes_y = 8.0;
1453             }
1454             v->block_height256_bytes_c = 0.0;
1455         }
1456         else {
1457             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1458                 v->block_height256_bytes_y = 1.0;
1459                 v->block_height256_bytes_c = 1.0;
1460             }
1461             else if (v->source_pixel_format[k] == dcn_bw_yuv420_sub_8) {
1462                 v->block_height256_bytes_y = 16.0;
1463                 v->block_height256_bytes_c = 8.0;
1464             }
1465             else {
1466                 v->block_height256_bytes_y = 8.0;
1467                 v->block_height256_bytes_c = 8.0;
1468             }
1469         }
1470         if (v->dcc_enable[k] == dcn_bw_yes) {
1471             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);
1472             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;
1473             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;
1474             if (v->pte_enable == dcn_bw_yes) {
1475                 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;
1476             }
1477             else {
1478                 v->meta_pte_bytes_frame_y = 0.0;
1479             }
1480             if (v->source_scan[k] == dcn_bw_hor) {
1481                 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;
1482             }
1483             else {
1484                 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;
1485             }
1486         }
1487         else {
1488             v->meta_pte_bytes_frame_y = 0.0;
1489             v->meta_row_byte_y = 0.0;
1490         }
1491         if (v->pte_enable == dcn_bw_yes) {
1492             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1493                 v->macro_tile_size_byte_y = 256.0;
1494                 v->macro_tile_height_y = 1.0;
1495             }
1496             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) {
1497                 v->macro_tile_size_byte_y = 4096.0;
1498                 v->macro_tile_height_y = 4.0 * v->block_height256_bytes_y;
1499             }
1500             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) {
1501                 v->macro_tile_size_byte_y = 64.0 * 1024;
1502                 v->macro_tile_height_y = 16.0 * v->block_height256_bytes_y;
1503             }
1504             else {
1505                 v->macro_tile_size_byte_y = 256.0 * 1024;
1506                 v->macro_tile_height_y = 32.0 * v->block_height256_bytes_y;
1507             }
1508             if (v->macro_tile_size_byte_y <= 65536.0) {
1509                 v->pixel_pte_req_height_y = v->macro_tile_height_y;
1510             }
1511             else {
1512                 v->pixel_pte_req_height_y = 16.0 * v->block_height256_bytes_y;
1513             }
1514             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;
1515             if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1516                 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);
1517             }
1518             else if (v->source_scan[k] == dcn_bw_hor) {
1519                 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);
1520             }
1521             else {
1522                 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);
1523             }
1524         }
1525         else {
1526             v->pixel_pte_bytes_per_row_y = 0.0;
1527         }
1528         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)) {
1529             if (v->dcc_enable[k] == dcn_bw_yes) {
1530                 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);
1531                 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;
1532                 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;
1533                 if (v->pte_enable == dcn_bw_yes) {
1534                     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;
1535                 }
1536                 else {
1537                     v->meta_pte_bytes_frame_c = 0.0;
1538                 }
1539                 if (v->source_scan[k] == dcn_bw_hor) {
1540                     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;
1541                 }
1542                 else {
1543                     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;
1544                 }
1545             }
1546             else {
1547                 v->meta_pte_bytes_frame_c = 0.0;
1548                 v->meta_row_byte_c = 0.0;
1549             }
1550             if (v->pte_enable == dcn_bw_yes) {
1551                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1552                     v->macro_tile_size_bytes_c = 256.0;
1553                     v->macro_tile_height_c = 1.0;
1554                 }
1555                 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) {
1556                     v->macro_tile_size_bytes_c = 4096.0;
1557                     v->macro_tile_height_c = 4.0 * v->block_height256_bytes_c;
1558                 }
1559                 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) {
1560                     v->macro_tile_size_bytes_c = 64.0 * 1024;
1561                     v->macro_tile_height_c = 16.0 * v->block_height256_bytes_c;
1562                 }
1563                 else {
1564                     v->macro_tile_size_bytes_c = 256.0 * 1024;
1565                     v->macro_tile_height_c = 32.0 * v->block_height256_bytes_c;
1566                 }
1567                 if (v->macro_tile_size_bytes_c <= 65536.0) {
1568                     v->pixel_pte_req_height_c = v->macro_tile_height_c;
1569                 }
1570                 else {
1571                     v->pixel_pte_req_height_c = 16.0 * v->block_height256_bytes_c;
1572                 }
1573                 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;
1574                 if (v->source_surface_mode[k] == dcn_bw_sw_linear) {
1575                     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);
1576                 }
1577                 else if (v->source_scan[k] == dcn_bw_hor) {
1578                     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);
1579                 }
1580                 else {
1581                     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);
1582                 }
1583             }
1584             else {
1585                 v->pixel_pte_bytes_per_row_c = 0.0;
1586             }
1587         }
1588         else {
1589             v->pixel_pte_bytes_per_row_c = 0.0;
1590             v->meta_pte_bytes_frame_c = 0.0;
1591             v->meta_row_byte_c = 0.0;
1592         }
1593         v->pixel_pte_bytes_per_row[k] = v->pixel_pte_bytes_per_row_y + v->pixel_pte_bytes_per_row_c;
1594         v->meta_pte_bytes_frame[k] = v->meta_pte_bytes_frame_y + v->meta_pte_bytes_frame_c;
1595         v->meta_row_byte[k] = v->meta_row_byte_y + v->meta_row_byte_c;
1596         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);
1597         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;
1598         if (v->v_init_pre_fill_y[k] > 1.0) {
1599             v->max_partial_swath_y =dcn_bw_mod((v->v_init_pre_fill_y[k] - 2.0), v->swath_height_y[k]);
1600         }
1601         else {
1602             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]);
1603         }
1604         v->max_partial_swath_y =dcn_bw_max2(1.0, v->max_partial_swath_y);
1605         v->prefetch_source_lines_y[k] = v->max_num_swath_y[k] * v->swath_height_y[k] + v->max_partial_swath_y;
1606         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)) {
1607             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);
1608             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;
1609             if (v->v_init_pre_fill_c[k] > 1.0) {
1610                 v->max_partial_swath_c =dcn_bw_mod((v->v_init_pre_fill_c[k] - 2.0), v->swath_height_c[k]);
1611             }
1612             else {
1613                 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]);
1614             }
1615             v->max_partial_swath_c =dcn_bw_max2(1.0, v->max_partial_swath_c);
1616         }
1617         else {
1618             v->max_num_swath_c[k] = 0.0;
1619             v->max_partial_swath_c = 0.0;
1620         }
1621         v->prefetch_source_lines_c[k] = v->max_num_swath_c[k] * v->swath_height_c[k] + v->max_partial_swath_c;
1622     }
1623     v->t_calc = 24.0 / v->dcf_clk_deep_sleep;
1624     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1625         if (v->can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one == dcn_bw_yes) {
1626             v->max_vstartup_lines[k] = v->vtotal[k] - v->vactive[k] - 1.0;
1627         }
1628         else {
1629             v->max_vstartup_lines[k] = v->v_sync_plus_back_porch[k] - 1.0;
1630         }
1631     }
1632     v->next_prefetch_mode = 0.0;
1633     do {
1634         v->v_startup_lines = 13.0;
1635         do {
1636             v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_yes;
1637             v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_no;
1638             v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_no;
1639             v->v_ratio_prefetch_more_than4 = dcn_bw_no;
1640             v->destination_line_times_for_prefetch_less_than2 = dcn_bw_no;
1641             v->prefetch_mode = v->next_prefetch_mode;
1642             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1643                 v->dstx_after_scaler = 90.0 * v->pixel_clock[k] / v->dppclk + 42.0 * v->pixel_clock[k] / v->dispclk;
1644                 if (v->dpp_per_plane[k] > 1.0) {
1645                     v->dstx_after_scaler = v->dstx_after_scaler + v->scaler_rec_out_width[k] / 2.0;
1646                 }
1647                 if (v->output_format[k] == dcn_bw_420) {
1648                     v->dsty_after_scaler = 1.0;
1649                 }
1650                 else {
1651                     v->dsty_after_scaler = 0.0;
1652                 }
1653                 v->v_update_offset_pix[k] = dcn_bw_ceil2(v->htotal[k] / 4.0, 1.0);
1654                 v->total_repeater_delay_time = v->max_inter_dcn_tile_repeaters * (2.0 / v->dppclk + 3.0 / v->dispclk);
1655                 v->v_update_width_pix[k] = (14.0 / v->dcf_clk_deep_sleep + 12.0 / v->dppclk + v->total_repeater_delay_time) * v->pixel_clock[k];
1656                 v->v_ready_offset_pix[k] = dcn_bw_max2(150.0 / v->dppclk, v->total_repeater_delay_time + 20.0 / v->dcf_clk_deep_sleep + 10.0 / v->dppclk) * v->pixel_clock[k];
1657                 v->t_setup = (v->v_update_offset_pix[k] + v->v_update_width_pix[k] + v->v_ready_offset_pix[k]) / v->pixel_clock[k];
1658                 v->v_startup[k] =dcn_bw_min2(v->v_startup_lines, v->max_vstartup_lines[k]);
1659                 if (v->prefetch_mode == 0.0) {
1660                     v->t_wait =dcn_bw_max3(v->dram_clock_change_latency + v->urgent_latency, v->sr_enter_plus_exit_time, v->urgent_latency);
1661                 }
1662                 else if (v->prefetch_mode == 1.0) {
1663                     v->t_wait =dcn_bw_max2(v->sr_enter_plus_exit_time, v->urgent_latency);
1664                 }
1665                 else {
1666                     v->t_wait = v->urgent_latency;
1667                 }
1668                 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;
1669                 if (v->destination_lines_for_prefetch[k] > 0.0) {
1670                     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]);
1671                 }
1672                 else {
1673                     v->prefetch_bandwidth[k] = 999999.0;
1674                 }
1675             }
1676             v->bandwidth_available_for_immediate_flip = v->return_bw;
1677             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1678                 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]);
1679             }
1680             v->tot_immediate_flip_bytes = 0.0;
1681             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1682                 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)) {
1683                     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];
1684                 }
1685             }
1686             v->max_rd_bandwidth = 0.0;
1687             for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1688                 if (v->pte_enable == dcn_bw_yes && v->dcc_enable[k] == dcn_bw_yes) {
1689                     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)) {
1690                         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);
1691                     }
1692                     else {
1693                         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);
1694                     }
1695                 }
1696                 else {
1697                     v->time_for_fetching_meta_pte = v->htotal[k] / v->pixel_clock[k] / 4.0;
1698                 }
1699                 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;
1700                 if ((v->pte_enable == dcn_bw_yes || v->dcc_enable[k] == dcn_bw_yes)) {
1701                     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)) {
1702                         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);
1703                     }
1704                     else {
1705                         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);
1706                     }
1707                 }
1708                 else {
1709                     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);
1710                 }
1711                 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;
1712                 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];
1713                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
1714                     v->v_ratio_prefetch_y[k] = v->prefetch_source_lines_y[k] / v->lines_to_request_prefetch_pixel_data;
1715                     if ((v->swath_height_y[k] > 4.0)) {
1716                         if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_y[k] - 3.0) / 2.0) {
1717                             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));
1718                         }
1719                         else {
1720                             v->v_ratio_prefetch_y[k] = 999999.0;
1721                         }
1722                     }
1723                 }
1724                 else {
1725                     v->v_ratio_prefetch_y[k] = 999999.0;
1726                 }
1727                 v->v_ratio_prefetch_y[k] =dcn_bw_max2(v->v_ratio_prefetch_y[k], 1.0);
1728                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
1729                     v->v_ratio_prefetch_c[k] = v->prefetch_source_lines_c[k] / v->lines_to_request_prefetch_pixel_data;
1730                     if ((v->swath_height_c[k] > 4.0)) {
1731                         if (v->lines_to_request_prefetch_pixel_data > (v->v_init_pre_fill_c[k] - 3.0) / 2.0) {
1732                             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));
1733                         }
1734                         else {
1735                             v->v_ratio_prefetch_c[k] = 999999.0;
1736                         }
1737                     }
1738                 }
1739                 else {
1740                     v->v_ratio_prefetch_c[k] = 999999.0;
1741                 }
1742                 v->v_ratio_prefetch_c[k] =dcn_bw_max2(v->v_ratio_prefetch_c[k], 1.0);
1743                 if (v->lines_to_request_prefetch_pixel_data > 0.0) {
1744                     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]);
1745                 }
1746                 else {
1747                     v->required_prefetch_pix_data_bw = 999999.0;
1748                 }
1749                 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);
1750                 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)) {
1751                     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]));
1752                 }
1753                 if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) {
1754                     v->v_ratio_prefetch_more_than4 = dcn_bw_yes;
1755                 }
1756                 if (v->destination_lines_for_prefetch[k] < 2.0) {
1757                     v->destination_line_times_for_prefetch_less_than2 = dcn_bw_yes;
1758                 }
1759                 if (v->max_vstartup_lines[k] > v->v_startup_lines) {
1760                     if (v->required_prefetch_pix_data_bw > (v->read_bandwidth_plane_luma[k] + v->read_bandwidth_plane_chroma[k])) {
1761                         v->planes_with_room_to_increase_vstartup_prefetch_bw_less_than_active_bw = dcn_bw_no;
1762                     }
1763                     if (v->v_ratio_prefetch_y[k] > 4.0 || v->v_ratio_prefetch_c[k] > 4.0) {
1764                         v->planes_with_room_to_increase_vstartup_vratio_prefetch_more_than4 = dcn_bw_yes;
1765                     }
1766                     if (v->destination_lines_for_prefetch[k] < 2.0) {
1767                         v->planes_with_room_to_increase_vstartup_destination_line_times_for_prefetch_less_than2 = dcn_bw_yes;
1768                     }
1769                 }
1770             }
1771             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) {
1772                 v->prefetch_mode_supported = dcn_bw_yes;
1773             }
1774             else {
1775                 v->prefetch_mode_supported = dcn_bw_no;
1776             }
1777             v->v_startup_lines = v->v_startup_lines + 1.0;
1778         } 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)));
1779         v->next_prefetch_mode = v->next_prefetch_mode + 1.0;
1780     } while (!(v->prefetch_mode_supported == dcn_bw_yes || v->prefetch_mode == 2.0));
1781     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1782         if (v->v_ratio_prefetch_y[k] <= 1.0) {
1783             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];
1784         }
1785         else {
1786             v->display_pipe_line_delivery_time_luma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
1787         }
1788         if (v->byte_per_pixel_detc[k] == 0.0) {
1789             v->display_pipe_line_delivery_time_chroma_prefetch[k] = 0.0;
1790         }
1791         else {
1792             if (v->v_ratio_prefetch_c[k] <= 1.0) {
1793                 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];
1794             }
1795             else {
1796                 v->display_pipe_line_delivery_time_chroma_prefetch[k] = v->swath_width_y[k] / v->pscl_throughput[k] / v->dppclk;
1797             }
1798         }
1799     }
1800     /*min ttuv_blank*/
1801 
1802     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1803         if (v->prefetch_mode == 0.0) {
1804             v->allow_dram_clock_change_during_vblank[k] = dcn_bw_yes;
1805             v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes;
1806             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);
1807         }
1808         else if (v->prefetch_mode == 1.0) {
1809             v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no;
1810             v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_yes;
1811             v->min_ttuv_blank[k] = v->t_calc +dcn_bw_max2(v->stutter_enter_plus_exit_watermark, v->urgent_watermark);
1812         }
1813         else {
1814             v->allow_dram_clock_change_during_vblank[k] = dcn_bw_no;
1815             v->allow_dram_self_refresh_during_vblank[k] = dcn_bw_no;
1816             v->min_ttuv_blank[k] = v->t_calc + v->urgent_watermark;
1817         }
1818     }
1819     /*nb p-state/dram clock change support*/
1820 
1821     v->active_dp_ps = 0.0;
1822     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1823         v->active_dp_ps = v->active_dp_ps + v->dpp_per_plane[k];
1824     }
1825     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1826         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);
1827         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);
1828         v->effective_lb_latency_hiding_y = v->lb_latency_hiding_source_lines_y / v->v_ratio[k] * (v->htotal[k] / v->pixel_clock[k]);
1829         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]);
1830         if (v->swath_width_y[k] > 2.0 * v->dpp_output_buffer_pixels) {
1831             v->dpp_output_buffer_lines_y = v->dpp_output_buffer_pixels / v->swath_width_y[k];
1832         }
1833         else if (v->swath_width_y[k] > v->dpp_output_buffer_pixels) {
1834             v->dpp_output_buffer_lines_y = 0.5;
1835         }
1836         else {
1837             v->dpp_output_buffer_lines_y = 1.0;
1838         }
1839         if (v->swath_width_y[k] / 2.0 > 2.0 * v->dpp_output_buffer_pixels) {
1840             v->dpp_output_buffer_lines_c = v->dpp_output_buffer_pixels / (v->swath_width_y[k] / 2.0);
1841         }
1842         else if (v->swath_width_y[k] / 2.0 > v->dpp_output_buffer_pixels) {
1843             v->dpp_output_buffer_lines_c = 0.5;
1844         }
1845         else {
1846             v->dpp_output_buffer_lines_c = 1.0;
1847         }
1848         v->dppopp_buffering_y = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_y + v->opp_output_buffer_lines);
1849         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]);
1850         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;
1851         if (v->active_dp_ps > 1.0) {
1852             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]);
1853         }
1854         if (v->byte_per_pixel_detc[k] > 0.0) {
1855             v->dppopp_buffering_c = (v->htotal[k] / v->pixel_clock[k]) * (v->dpp_output_buffer_lines_c + v->opp_output_buffer_lines);
1856             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]);
1857             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;
1858             if (v->active_dp_ps > 1.0) {
1859                 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]);
1860             }
1861             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);
1862         }
1863         else {
1864             v->active_dram_clock_change_latency_margin[k] = v->active_dram_clock_change_latency_margin_y;
1865         }
1866         if (v->output_format[k] == dcn_bw_444) {
1867             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;
1868         }
1869         else {
1870             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;
1871         }
1872         if (v->output[k] == dcn_bw_writeback) {
1873             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);
1874         }
1875     }
1876     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1877         if (v->allow_dram_clock_change_during_vblank[k] == dcn_bw_yes) {
1878             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);
1879         }
1880         else {
1881             v->v_blank_dram_clock_change_latency_margin[k] = 0.0;
1882         }
1883     }
1884     v->min_active_dram_clock_change_margin = 999999.0;
1885     v->v_blank_of_min_active_dram_clock_change_margin = 999999.0;
1886     v->second_min_active_dram_clock_change_margin = 999999.0;
1887     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1888         if (v->active_dram_clock_change_latency_margin[k] < v->min_active_dram_clock_change_margin) {
1889             v->second_min_active_dram_clock_change_margin = v->min_active_dram_clock_change_margin;
1890             v->min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k];
1891             v->v_blank_of_min_active_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k];
1892         }
1893         else if (v->active_dram_clock_change_latency_margin[k] < v->second_min_active_dram_clock_change_margin) {
1894             v->second_min_active_dram_clock_change_margin = v->active_dram_clock_change_latency_margin[k];
1895         }
1896     }
1897     v->min_vblank_dram_clock_change_margin = 999999.0;
1898     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1899         if (v->min_vblank_dram_clock_change_margin > v->v_blank_dram_clock_change_latency_margin[k]) {
1900             v->min_vblank_dram_clock_change_margin = v->v_blank_dram_clock_change_latency_margin[k];
1901         }
1902     }
1903     if (v->synchronized_vblank == dcn_bw_yes || v->number_of_active_planes == 1) {
1904         v->dram_clock_change_margin =dcn_bw_max2(v->min_active_dram_clock_change_margin, v->min_vblank_dram_clock_change_margin);
1905     }
1906     else if (v->v_blank_of_min_active_dram_clock_change_margin > v->min_active_dram_clock_change_margin) {
1907         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);
1908     }
1909     else {
1910         v->dram_clock_change_margin = v->min_active_dram_clock_change_margin;
1911     }
1912     if (v->min_active_dram_clock_change_margin > 0.0) {
1913         v->dram_clock_change_support = dcn_bw_supported_in_v_active;
1914     }
1915     else if (v->dram_clock_change_margin > 0.0) {
1916         v->dram_clock_change_support = dcn_bw_supported_in_v_blank;
1917     }
1918     else {
1919         v->dram_clock_change_support = dcn_bw_not_supported;
1920     }
1921     /*maximum bandwidth used*/
1922 
1923     v->wr_bandwidth = 0.0;
1924     for (k = 0; k <= v->number_of_active_planes - 1; k++) {
1925         if (v->output[k] == dcn_bw_writeback && v->output_format[k] == dcn_bw_444) {
1926             v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 4.0;
1927         }
1928         else if (v->output[k] == dcn_bw_writeback) {
1929             v->wr_bandwidth = v->wr_bandwidth + v->scaler_rec_out_width[k] / (v->htotal[k] / v->pixel_clock[k]) * 1.5;
1930         }
1931     }
1932     v->max_used_bw = v->max_rd_bandwidth + v->wr_bandwidth;
1933 }